diff options
author | Silvio Rhatto <rhatto@riseup.net> | 2013-12-10 13:38:46 -0200 |
---|---|---|
committer | Silvio Rhatto <rhatto@riseup.net> | 2013-12-10 13:38:46 -0200 |
commit | f695f7810ac91d9cd3f576dcb58f41e75e720129 (patch) | |
tree | b16d1eda41808283d3629bc0aca6e94f95c13aa5 | |
parent | cd69cba65cdb39135f44d83537869086ed2330b0 (diff) | |
download | keyringer-f695f7810ac91d9cd3f576dcb58f41e75e720129.tar.gz keyringer-f695f7810ac91d9cd3f576dcb58f41e75e720129.tar.bz2 |
Enhanced 'cd' behavior (#34)
-rwxr-xr-x | lib/keyringer/actions/shell | 16 |
1 files changed, 12 insertions, 4 deletions
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" |