Last active
March 21, 2025 07:29
-
-
Save mbigras/3c855d54f7700dbd55e311a56ddbb5e2 to your computer and use it in GitHub Desktop.
Experiments with different "e" scripts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# e - list files sorted by time, also filter and edit if only 1 match | |
# usage: e pattern1 pattern2 ... | |
pattern=$(echo "$@" | awk ' | |
BEGIN { printf "//" } | |
{ for (i = 1; i <= NF; i++) | |
printf(" && /%s/", $i) }') | |
matches=$(ls -t | tac | awk "$pattern") | |
echo "$matches" | |
if test $(echo "$matches" | wc -l) -eq 1 | |
then | |
ed "$matches" | |
fi |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# e - list files sorted by time, also filter and edit if only 1 match | |
# usage: e pattern1 pattern2 ... | |
ls -t | awk ' | |
BEGIN { | |
for (i = 1; ARGV[i] != "-"; i++) { # collect patterns | |
pat[++np] = ARGV[i] | |
ARGV[i] = "" | |
} | |
} | |
{ for (i = 1; i <= np; i++) { | |
if (!match($0, pat[i])) next | |
} | |
nm++; fn=$0; print | |
} | |
END { if (nm == 1) | |
system(sprintf("rlwrap ed </dev/tty \"%s\"", fn)) | |
} | |
' "$@" - |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# e - list files sorted by time, also filter and edit if only 1 match | |
# usage: e pattern1 pattern2 ... | |
f=$(mktemp) | |
m=$(mktemp) | |
printf '/%s/ && ' "" "$@" | awk '{ $NF=""; print }' >$f | |
ls -t | awk -f $f | tee $m | |
if test $(wc -l <$m) -eq 1 | |
then | |
exec rlwrap ed "$(cat $m)" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment