diff --git a/dfm b/dfm index 22416df..cc32790 100755 --- a/dfm +++ b/dfm @@ -56,6 +56,7 @@ prompt_base() { slash() { printf '%s' "$target/$sel" | rev | cut -b 1-2; } check() { file -E "$@" | grep "(No such file or directory)$"; } fullcmd() { + printf '%s\n' "$PWD" > "$cache_file" printf '%s' "$target" | sed -e "s/'/'\\\\''/g;s/\(.*\)/'\1'/" | cmd } @@ -70,11 +71,7 @@ prompt_base() { # Exit if the user presses Escape, Control-C, etc. exit_code=$? if [ "$exit_code" -ne 0 ]; then - if [ -f "$target" ]; then - printf '%s\n' "$(dirname "$(realpath -s "$target")")" > "$cache_file" - else - printf '%s\n' "$target" > "$cache_file" - fi + printf '%s\n' "$target" > "$cache_file" exit $exit_code fi @@ -108,12 +105,6 @@ prompt_base() { newt="$sel" fi - if [ -f "$newt" ]; then - printf '%s\n' "$(dirname "$(realpath -s "$newt")")" > "$cache_file" - else - printf '%s\n' "$newt" > "$cache_file" - fi - # If the current working directory is not empty if [ $(ls | wc -l) -ge 1 ]; then target="$newt" @@ -147,6 +138,13 @@ prompt_base() { fullcmd exit fi + # Target is a dollar sign, open TERMINAL + elif [ $(printf '%s' "$sel" | grep '\$' | wc -l) -gt 0 -a\ + "$open" = true ] + then + exec $TERMINAL -- sh -c "cd '$PWD'; exec $SHELL" &> /dev/null & + printf '%s\n' "$PWD" > "$cache_file" + exit # Target is a directory else PWD="$target" @@ -315,6 +313,8 @@ parse_opts() { target="$(realpath -s "$target")" PWD="$target" else + # Zero out cache file. + [ "$restore" = true -a -s "$cache_file" ] && > "$cache_file" printf '%s\n' "$PROGRAM_NAME: \`$target\` is not a directory." >&2 exit 2 fi