Skip to content

Instantly share code, notes, and snippets.

@mbigras
Last active March 21, 2025 07:29
Show Gist options
  • Select an option

  • Save mbigras/3c855d54f7700dbd55e311a56ddbb5e2 to your computer and use it in GitHub Desktop.

Select an option

Save mbigras/3c855d54f7700dbd55e311a56ddbb5e2 to your computer and use it in GitHub Desktop.

Revisions

  1. Max Bigras revised this gist Mar 21, 2025. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions e5.sh
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,5 @@
    # 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++)
  2. Max Bigras revised this gist Mar 21, 2025. 1 changed file with 10 additions and 0 deletions.
    10 changes: 10 additions & 0 deletions e5.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,10 @@
    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
  3. mbigras created this gist Mar 21, 2025.
    18 changes: 18 additions & 0 deletions e8.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,18 @@
    # 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))
    }
    ' "$@" -
    10 changes: 10 additions & 0 deletions e9.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,10 @@
    # 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