-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnext
More file actions
executable file
·55 lines (51 loc) · 1 KB
/
next
File metadata and controls
executable file
·55 lines (51 loc) · 1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#!/bin/bash
ITER="cur"
if [ $# -gt 0 ] && [ $1 = -i ]
then
ITER="$2"
fi
if [ $# -gt 0 ] && [ $1 = -h ]
then
cat <<EOF
next - iterate over files using a symbolic link as pointer
options:
-i ITERATORFILE
use ITERATORFILE instead of "./cur"
usage:
\$ next #initialize cur pointer
firstfile
\$ vi ./cur
\$ echo \$(readlink ./cur)
firstfile
\$ next #increment pointer
secondfile
\$ echo \$(readlink ./cur)
secondfile
\$ while [ -n "\`next\`" ] ; do echo \`readlink ./cur\`; done
EOF
exit
fi
ALL=$(find . -maxdepth 1 -printf "%f\n"|sed 1d|sed 's/^$ITER$//'|sort)
if [ ! -e $ITER ]
then
NEXT=$(pwd)/`echo "$ALL" | sed 1q`
else
CURFILE=$(basename "`readlink $ITER`")
CURFILE=$(printf '%q' "$CURFILE")
NEXT=$(echo "$ALL" |grep -A1 "^$CURFILE$")
NEXT=$(echo "$NEXT"|sed 1d)
if [ -z $NEXT ]
then
exit 1
fi
NEXT=$(pwd)/$NEXT
fi
if [ -e $ITER ]
then
rm $ITER
fi
echo $NEXT
if [ -e "$NEXT" ]
then
ln -s "$NEXT" $ITER
fi