summaryrefslogtreecommitdiff
path: root/lib/keyringer/actions/shell
diff options
context:
space:
mode:
authorSilvio Rhatto <rhatto@riseup.net>2013-12-10 13:23:06 -0200
committerSilvio Rhatto <rhatto@riseup.net>2013-12-10 13:23:06 -0200
commitcd69cba65cdb39135f44d83537869086ed2330b0 (patch)
treea164a70101d14c058dca55f7e42b0e776400838f /lib/keyringer/actions/shell
parent60603e9479414a67f96849f99851ef2749693f49 (diff)
downloadkeyringer-cd69cba65cdb39135f44d83537869086ed2330b0.tar.gz
keyringer-cd69cba65cdb39135f44d83537869086ed2330b0.tar.bz2
Initial code for 'cd' shell command (#34)
Diffstat (limited to 'lib/keyringer/actions/shell')
-rwxr-xr-xlib/keyringer/actions/shell32
1 files changed, 29 insertions, 3 deletions
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