about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--LICENSE2
-rw-r--r--NEWS.md20
-rw-r--r--README.md3
-rwxr-xr-xcontrib/lrls48
-rw-r--r--lr.14
-rw-r--r--lr.c21
6 files changed, 78 insertions, 20 deletions
diff --git a/LICENSE b/LICENSE
index 8792f35..23f09b4 100644
--- a/LICENSE
+++ b/LICENSE
@@ -1,6 +1,6 @@
 /* lr - a better recursive ls/find */
 
-Copyright (C) 2015-2020 Leah Neukirchen <purl.org/net/chneukirchen>
+Copyright (C) 2015-2023 Leah Neukirchen <purl.org/net/chneukirchen>
 Parts of code derived from musl libc, which is
 Copyright (C) 2005-2014 Rich Felker, et al.
 
diff --git a/NEWS.md b/NEWS.md
index ac29e44..2ebaf61 100644
--- a/NEWS.md
+++ b/NEWS.md
@@ -1,16 +1,22 @@
+## 1.6 (2023-08-05)
+
+* Feature: add -of to sort by file basename.
+* Bugfix: default to _FILE_OFFSET_BITS=64.
+* Small bugfixes.
+
 ## 1.5.1 (2020-01-18)
 
-* Bug: `-A` did not stop traversing hidden directories.
+* Bugfix: `-A` did not stop traversing hidden directories.
 
 ## 1.5 (2020-01-01)
 
 * Feature: add -W to sort results by name and print during traversal.
-* Bug: Make -B keep traversing even if file is not printed.
+* Bugfix: Make -B keep traversing even if file is not printed.
 * Small speed tweaks.
 
 ## 1.4.1 (2019-02-08)
 
-* Bugfix release
+* Bugfix release.
 
 ## 1.4 (2018-04-17)
 
@@ -41,7 +47,7 @@
 * Feature: new option `-X` to print OSC 8 hyperlinks.
 * Feature: new option `-e` for the common case of filtering file names.
 * Feature: support for DragonFlyBSD.
-* Bug: lr doesn't fail on symlinks refering to themselves anymore.
+* Bugfix: lr doesn't fail on symlinks refering to themselves anymore.
 
 ## 1.0 (2017-08-29)
 
@@ -55,7 +61,7 @@
 * Feature: new action `color <num>` to change the color of files.
 * Feature: new argument `@file` to read file names from a file.
 * Feature: negated string operations `!=`, `!===`, `!~~`, `!~`, `!=~~`.
-* Bug: lr now reports errors and sets exit code when toplevel
+* Bugfix: lr now reports errors and sets exit code when toplevel
   arguments can not be stat'ed.
 
 ## 0.4 (2017-04-25)
@@ -64,11 +70,11 @@
 
 ## 0.3.2 (2016-05-20)
 
-* Bug: getopt was called in a wrong way from ARM platforms
+* Bugfix: getopt was called in a wrong way from ARM platforms
 
 ## 0.3.1 (2016-03-31)
 
-* Bug: `=~` was not recognized (broken since 0.3)
+* Bugfix: `=~` was not recognized (broken since 0.3)
 * Add emacs contrib (lr.el)
 
 ## 0.3 (2016-02-28)
diff --git a/README.md b/README.md
index b82e25e..02fd773 100644
--- a/README.md
+++ b/README.md
@@ -128,6 +128,7 @@ Default: `n`.
 * `c`: ctime.
 * `d`: path depth.
 * `e`: file extension.
+* `f`: file basename.
 * `i`: inode number.
 * `m`: mtime.
 * `n`: file name.
@@ -321,6 +322,6 @@ You can also just copy the binary into your `PATH`.
 
 ## Copyright
 
-Copyright (C) 2015-2020 Leah Neukirchen <purl.org/net/chneukirchen>
+Copyright (C) 2015-2023 Leah Neukirchen <purl.org/net/chneukirchen>
 
 Licensed under the terms of the MIT license, see lr.c.
diff --git a/contrib/lrls b/contrib/lrls
index fc4b149..2d41447 100755
--- a/contrib/lrls
+++ b/contrib/lrls
@@ -1,8 +1,50 @@
 #!/bin/sh
 # lrls - lr with GNU ls style output
+#
+# Usage (Bash, Zsh):
+#
+#     # Clear any system-level aliases:
+#     unalias ls la ll 2>/dev/null
+#     alias ls='lslr -A'
+#     alias la='lslr'
+#     alias ll='lslr -lh'
 
-color=
-[ -t 1 ] && color=-GG
+use_strip=1
+check_depth=1
 
-lr $color -A1s  -t '!type == d || depth > 0' "$@" |git column --mode=dense --pad=2
+if [ -t 1 ]; then
+    use_color=1
+    use_column=1
+fi
 
+while getopts :01ABC:DFGHLQPST:UWXde:f:lho:st:x opt; do
+    case $opt in
+    # If we're not entering directories:
+    # - Avoid depth check so directory names aren't skipped entirely.
+    # - Avoid strip so directory names aren't replaced with dots.
+    d)  unset check_depth
+        unset use_strip
+        ;;
+    # Avoid git column for long lr output.
+    l)  unset use_column
+        ;;
+    esac
+done
+
+# If more than one path is given as an arg, strip can produce ambiguous output
+# for multi-segment paths (and has no effect on single-segment paths).
+if [ "$#" -gt "$OPTIND" ]; then
+    unset use_strip
+fi
+
+lr -1 \
+    ${use_color:+-GG} \
+    ${use_strip:+-s} \
+    ${check_depth:+-t '!type == d || depth > 0'} \
+    "$@" | {
+        if [ -n "$use_column" ]; then
+            git column --mode=dense --pad=2
+        else
+            cat
+        fi;
+    }
diff --git a/lr.1 b/lr.1
index 5082a8e..002bf87 100644
--- a/lr.1
+++ b/lr.1
@@ -1,4 +1,4 @@
-.Dd December 5, 2019
+.Dd August 26, 2022
 .Dt LR 1
 .Os
 .Sh NAME
@@ -322,6 +322,8 @@ ctime
 path depth
 .It Ic e
 file extension
+.It Ic f
+file basename
 .It Ic i
 inode number
 .It Ic m
diff --git a/lr.c b/lr.c
index 276abec..17236c5 100644
--- a/lr.c
+++ b/lr.c
@@ -1,7 +1,7 @@
 /* lr - a better recursive ls/find */
 
 /*
- * Copyright (C) 2015-2020 Leah Neukirchen <purl.org/net/chneukirchen>
+ * Copyright (C) 2015-2023 Leah Neukirchen <purl.org/net/chneukirchen>
  * Parts of code derived from musl libc, which is
  * Copyright (C) 2005-2014 Rich Felker, et al.
  *
@@ -31,6 +31,10 @@
 
 #define _GNU_SOURCE
 
+#ifndef _FILE_OFFSET_BITS
+#define _FILE_OFFSET_BITS 64
+#endif
+
 #include <sys/param.h>
 #include <sys/stat.h>
 #include <sys/types.h>
@@ -1459,6 +1463,8 @@ order(const void *a, const void *b)
 		              "ZZZZAZZZZZZZZZZZ"[(fa->sb.st_mode >> 12) & 0x0f]);
 		case 'n': STRCMP(fa->fpath, fb->fpath);
 		case 'N': STRCMP(fb->fpath, fa->fpath);
+		case 'f': STRCMP(basenam(fa->fpath), basenam(fb->fpath));
+		case 'F': STRCMP(basenam(fb->fpath), basenam(fa->fpath));
 		case 'e': STRCMP(extnam(fa->fpath), extnam(fb->fpath));
 		case 'E': STRCMP(extnam(fb->fpath), extnam(fa->fpath));
 		case 'p': DIRCMP(fa->fpath, fb->fpath);
@@ -1628,7 +1634,7 @@ color_size_on(off_t s)
 	else if (s <          512*1024LL) c = 226;
 	else if (s <         1024*1024LL) c = 220;
 	else if (s <     700*1024*1024LL) c = 214;
-	else if (s <  2*1048*1024*1024LL) c = 208;
+	else if (s <  2*1024*1024*1024LL) c = 208;
 	else if (s < 50*1024*1024*1024LL) c = 202;
 	else				  c = 196;
 
@@ -1649,7 +1655,7 @@ print_comma(int len, intmax_t i)
 		*--s = ',';
 	}
 
-	printf("%*.*s", len+len/3, len+len/3, s);
+	printf("%*s", len+len/3, s);
 }
 
 static void
@@ -1782,7 +1788,8 @@ print_noprefix(struct fileinfo *fi)
 	if (fi->prefixl == 0 && fi->fpath[0])
 		print_shquoted(fi->fpath);
 	else if (strlen(fi->fpath) > fi->prefixl + 1)  /* strip prefix */
-		print_shquoted(fi->fpath + fi->prefixl + 1);
+		print_shquoted(fi->fpath + fi->prefixl +
+		    (fi->fpath[fi->prefixl] == '/'));
 	else if (S_ISDIR(fi->sb.st_mode))  /* turn empty string into "." */
 		printf(".");
 	else  /* turn empty string into basename */
@@ -2247,7 +2254,7 @@ static int
 recurse(char *path, struct history *h, int guessdir)
 {
 	size_t l = strlen(path), j = l && path[l-1] == '/' ? l - 1 : l;
-	struct stat st;
+	struct stat st = { 0 };
 	struct history new;
 	int r;
 	ino_t entries;
@@ -2264,7 +2271,7 @@ recurse(char *path, struct history *h, int guessdir)
 	if (need_stat)
 		guessdir = 1;
 
-	if (guessdir && (resolve ? stat(fpath, &st) : lstat(fpath, &st) < 0)) {
+	if (guessdir && (resolve ? stat(fpath, &st) : lstat(fpath, &st)) < 0) {
 		if (resolve && (errno == ENOENT || errno == ELOOP) &&
 		    !lstat(fpath, &st)) {
 			/* ignore */
@@ -2495,7 +2502,7 @@ main(int argc, char *argv[])
 			Gflag += 2;  /* force color on */
 			break;
 		case 'D': Dflag++; Bflag = 0; break;
-		case 'F': format = type_format; break;
+		case 'F': if (!lflag) format = type_format; break;
 		case 'G': Gflag++; break;
 		case 'H': Hflag++; break;
 		case 'L': Lflag++; break;