summaryrefslogtreecommitdiff
path: root/lib/keyringer/actions/shell
diff options
context:
space:
mode:
Diffstat (limited to 'lib/keyringer/actions/shell')
-rwxr-xr-xlib/keyringer/actions/shell57
1 files changed, 57 insertions, 0 deletions
diff --git a/lib/keyringer/actions/shell b/lib/keyringer/actions/shell
new file mode 100755
index 0000000..ab170b1
--- /dev/null
+++ b/lib/keyringer/actions/shell
@@ -0,0 +1,57 @@
+#!/bin/bash
+#
+# Interactive shell.
+#
+
+# Load functions
+LIB="`dirname $0`/../functions"
+source "$LIB" || exit 1
+
+# Basic parameters
+SHELLPATH="/"
+
+# Show usage
+keyringer_usage $KEYRING
+
+# While a "quit" command isn't entered, read STDIN
+while read -rep "keyringer:/${KEYRING}${SHELLPATH}> " STDIN; do
+ if [ "$STDIN" == "quit" ] || [ "$STDIN" == "exit" ] || [ "$STDIN" == "bye" ]; then
+ break
+ elif [ "$STDIN" == "shell" ]; then
+ echo "Why you need nesting?"
+ 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" == "/" ] || [ "$SHELLPATH" == "" ]; then
+ SHELLPATH="/"
+ elif [[ "$SHELLPATH" == ".."* ]]; then
+ ARGS="$SHELLPATH"
+ SHELLPATH="$OLDPATH"
+ for colons in `echo $ARGS | sed -e 's|/| |g'`; do
+ 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"
+ SHELLPATH="$OLDPATH"
+ fi
+
+ elif [[ -n "$STDIN" && "$STDIN" != "#"* ]]; then
+ # If line is not empty or commented, process command
+ RELATIVE_PATH="$SHELLPATH" keyringer "$KEYRING" $STDIN
+ fi
+done