summaryrefslogtreecommitdiff
path: root/ce
diff options
context:
space:
mode:
Diffstat (limited to 'ce')
-rwxr-xr-xce17
1 files changed, 8 insertions, 9 deletions
diff --git a/ce b/ce
index e5e42e1..7d21ef2 100755
--- a/ce
+++ b/ce
@@ -1,12 +1,11 @@
-#!/bin/bash
+#!/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. Depends on: sed, ed, rlwrap, grep
-[ "$1" = "$HOME" ] && echo $HOME && exit ;
-fl="$HOME/.local/share/dir_lst"; [ ! -f "$fl" ] && echo -e "\n" > "$fl"
-[ "$2" = '!' ] && echo $1 && exit || \
-ln=`grep -n "$1" "$fl" | head -n 1 | cut -d : -f 1`; if [ -n "$1" ]; then
-if [ -n "$ln" ]; then echo -e "$ln m0\n1p\nw" | ed -s "$fl" || echo \?;
-else l="$1"; while [ ! -d "$l" ]; do echo \?; l="$(rlwrap -P$PWD/ -co cat -)";
-done; 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
+[ "$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 -n1 | cut -d: -f1`; if [ -n "$1" ]; then
+if [ -n "$ln" ]; then printf "$ln m0\n1p\nw\n" | ed -s "$fl" || echo \?;
+else l=$(realpath "$1"); while [ ! -d "$l" ]; do echo \?;
+l="$(rlwrap -P$PWD/ -co cat -)"; done; printf "0i\n$l\n.\nw\n" |\
+ed -s "$fl"; sed -i '43,$d' "$fl"; fi; else printf "2 m0\nw\n" | ed -s "$fl"; fi