change rotdir to use ed(1)
This commit is contained in:
parent
b74f98ede6
commit
53c42a5d00
1 changed files with 15 additions and 2 deletions
|
@ -1,3 +1,16 @@
|
|||
#!/bin/sh
|
||||
# Give this script a filename argument. Returns PWD rotated with that file first.
|
||||
ls "$PWD" | awk "BEGIN { lines = \"\"; m = 0; } /^$1$/ { m = 1; } { if (!m) { if (lines) { lines = lines\"\n\"; } lines = lines\"\"\$0; } else { print \$0; } } END { print lines; }"
|
||||
if [ -z "$1" ]; then
|
||||
echo usage: rotdir regex 2>&1
|
||||
exit 1;
|
||||
fi
|
||||
|
||||
ed -s <<EOF
|
||||
# Read in all files in the current dir
|
||||
r !find "$PWD" -maxdepth 1
|
||||
# Search all lines for regex, move to top
|
||||
g/$1/m0
|
||||
# Print all lines
|
||||
,p
|
||||
# Force quit
|
||||
Q
|
||||
EOF
|
||||
|
|
Loading…
Reference in a new issue