From f695f7810ac91d9cd3f576dcb58f41e75e720129 Mon Sep 17 00:00:00 2001 From: Silvio Rhatto Date: Tue, 10 Dec 2013 13:38:46 -0200 Subject: Enhanced 'cd' behavior (#34) --- lib/keyringer/actions/shell | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) (limited to 'lib') diff --git a/lib/keyringer/actions/shell b/lib/keyringer/actions/shell index d8a0ef7..d9a3e07 100755 --- a/lib/keyringer/actions/shell +++ b/lib/keyringer/actions/shell @@ -18,19 +18,27 @@ while read -rep "keyringer:/${KEYRING}${SHELLPATH}> " STDIN; do # Update current path OLDPATH="$SHELLPATH" - SHELLPATH="/`echo $STDIN | sed -e 's/^cd//' | cut -d ' ' -f 2`" + SHELLPATH="`echo $STDIN | sed -e 's/^cd//' | cut -d ' ' -f 2`" # Fix current path - if [ "$SHELLPATH" == "/" ]; then + if [ "$SHELLPATH" == "/" ] || [ "$SHELLPATH" == "" ]; then SHELLPATH="/" - elif [[ "$SHELLPATH" == "/.."* ]]; then + elif [[ "$SHELLPATH" == ".."* ]]; then ARGS="$SHELLPATH" SHELLPATH="$OLDPATH" for colons in `echo $ARGS | sed -e 's|/| |g'`; do - SHELLPATH="`dirname $SHELLPATH`" + SHELLPATH="`dirname $SHELLPATH | sed -e 's|^\.||'`" done fi + # Ensure path is absolute + if echo "$SHELLPATH" | grep -v -q -e "^/"; then + SHELLPATH="/$OLDPATH/$SHELLPATH" + fi + + # Removing multiple slashes + SHELLPATH="`echo $SHELLPATH | sed -e 's/\/\+/\//g'`" + # Check if path exists if [ ! -d "$KEYDIR/$SHELLPATH" ]; then echo "No such folder $SHELLPATH" -- cgit v1.2.3