]> gitweb.fluxo.info Git - keyringer.git/commitdiff
Initial code for 'cd' shell command (#34)
authorSilvio Rhatto <rhatto@riseup.net>
Tue, 10 Dec 2013 15:23:06 +0000 (13:23 -0200)
committerSilvio Rhatto <rhatto@riseup.net>
Tue, 10 Dec 2013 15:23:06 +0000 (13:23 -0200)
lib/keyringer/actions/shell

index c70d6bb1897bb6aa82d7430275cec61d28052800..d8a0ef7d49939a7e25fe2c3bd5147cbf30e4bc3f 100755 (executable)
@@ -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