aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorSilvio Rhatto <rhatto@riseup.net>2013-12-10 13:38:46 -0200
committerSilvio Rhatto <rhatto@riseup.net>2013-12-10 13:38:46 -0200
commitf695f7810ac91d9cd3f576dcb58f41e75e720129 (patch)
treeb16d1eda41808283d3629bc0aca6e94f95c13aa5 /lib
parentcd69cba65cdb39135f44d83537869086ed2330b0 (diff)
downloadkeyringer-f695f7810ac91d9cd3f576dcb58f41e75e720129.tar.gz
keyringer-f695f7810ac91d9cd3f576dcb58f41e75e720129.tar.bz2
Enhanced 'cd' behavior (#34)
Diffstat (limited to 'lib')
-rwxr-xr-xlib/keyringer/actions/shell16
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"