From: Silvio Rhatto Date: Tue, 10 Dec 2013 15:23:06 +0000 (-0200) Subject: Initial code for 'cd' shell command (#34) X-Git-Tag: 0.3~29 X-Git-Url: https://gitweb.fluxo.info/?a=commitdiff_plain;h=cd69cba65cdb39135f44d83537869086ed2330b0;p=keyringer.git Initial code for 'cd' shell command (#34) --- diff --git a/lib/keyringer/actions/shell b/lib/keyringer/actions/shell index c70d6bb..d8a0ef7 100755 --- a/lib/keyringer/actions/shell +++ b/lib/keyringer/actions/shell @@ -7,12 +7,38 @@ LIB="`dirname $0`/../functions" source "$LIB" || exit 1 +# Basic parameters +SHELLPATH="/" + # While a "quit" command isn't entered, read STDIN -while read -rep "keyringer:/> " STDIN; do +while read -rep "keyringer:/${KEYRING}${SHELLPATH}> " STDIN; do if [ "$STDIN" == "quit" ]; then break - # If line is not empty or commented, process command + elif [[ "$STDIN" == "cd"* ]]; then + + # Update current path + OLDPATH="$SHELLPATH" + SHELLPATH="/`echo $STDIN | sed -e 's/^cd//' | cut -d ' ' -f 2`" + + # Fix current path + if [ "$SHELLPATH" == "/" ]; then + SHELLPATH="/" + elif [[ "$SHELLPATH" == "/.."* ]]; then + ARGS="$SHELLPATH" + SHELLPATH="$OLDPATH" + for colons in `echo $ARGS | sed -e 's|/| |g'`; do + SHELLPATH="`dirname $SHELLPATH`" + done + fi + + # Check if path exists + if [ ! -d "$KEYDIR/$SHELLPATH" ]; then + echo "No such folder $SHELLPATH" + SHELLPATH="$OLDPATH" + fi + elif [[ -n "$STDIN" && "$STDIN" != "#"* ]]; then - keyringer "$KEYRING" $STDIN + # If line is not empty or commented, process command + RELATIVE_PATH="$SHELLPATH" keyringer "$KEYRING" $STDIN fi done