summaryrefslogtreecommitdiff
path: root/ce
blob: 9ca54e9b44a465933c6d248ef182dcc983d07377 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
#!/usr/bin/env sh
# Smart directory changer using the power of grep ;)
# source in a function j() { ce $*; cd `head -n 1 ~/.local/share/dir_lst` }
# or some such
[ "$1" = "$HOME" ] && echo $HOME && exit
fl="$HOME/.local/share/dir_lst"; [ ! -f "$fl" ] && touch "$fl"
[ "$2" = '!' ] && echo $1 && exit || \
ln=`grep -n "$1" "$fl" | head -n 1 | cut -d : -f 1`
if [ "$1" != "" ]; then if [ "$ln" != "" ]; then
echo -e "$ln m0\n1p\nw" | ed -s "$fl" || echo \?; else
l=$1; while [ ! -d "$l" ]; do echo \?; read l; [ ${l:(-1)} != / ] && l+=/; done;
l=`echo "$l" | sed "s|^[^/]|$PWD/&|"`;
echo -e "0i\n$l\n.\nw" | ed -s "$fl"; sed -i '43,$d' "$fl"
fi; else echo -e "2 m0\nw" | ed -s "$fl"; fi;