From 071b9ccc97eb5bd4b5401b29abdfcea10632741b Mon Sep 17 00:00:00 2001 From: Miguel Rodrigues Date: Sun, 16 Jul 2023 14:11:42 +0000 Subject: [PATCH 1/4] Zero cache file if path isn't a directory --- dfm | 2 ++ 1 file changed, 2 insertions(+) diff --git a/dfm b/dfm index 22416df..c41eccd 100755 --- a/dfm +++ b/dfm @@ -315,6 +315,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 From 74d3c752a680135f94c5ff96f7660d924e93c31e Mon Sep 17 00:00:00 2001 From: Miguel Rodrigues Date: Wed, 23 Aug 2023 21:01:10 +0000 Subject: [PATCH 2/4] fixes wildcard path restore and simplifies code --- dfm | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/dfm b/dfm index c41eccd..86566cd 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" From e29344d22b91c3baf4365a03d07d93cc50f200d0 Mon Sep 17 00:00:00 2001 From: Miguel Rodrigues Date: Wed, 23 Aug 2023 21:15:04 +0000 Subject: [PATCH 3/4] fix tabs --- dfm | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/dfm b/dfm index 86566cd..82d2f22 100755 --- a/dfm +++ b/dfm @@ -56,7 +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\n' "$PWD" > "$cache_file" printf '%s' "$target" | sed -e "s/'/'\\\\''/g;s/\(.*\)/'\1'/" | cmd } @@ -71,7 +71,7 @@ prompt_base() { # Exit if the user presses Escape, Control-C, etc. exit_code=$? if [ "$exit_code" -ne 0 ]; then - printf '%s\n' "$target" > "$cache_file" + printf '%s\n' "$target" > "$cache_file" exit $exit_code fi @@ -306,8 +306,8 @@ parse_opts() { target="$(realpath -s "$target")" PWD="$target" else - # Zero out cache file. - [ "$restore" = true -a -s "$cache_file" ] && > "$cache_file" + # 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 From 54583755587e49bd799c6b335e105fa05497600d Mon Sep 17 00:00:00 2001 From: Miguel Rodrigues Date: Fri, 25 Aug 2023 20:52:12 +0000 Subject: [PATCH 4/4] Add option to open shell. Type '$' and press 'Enter' to do so. Must be run with -o flag. If there are files with '$' escape like so '\$' to open shell. --- dfm | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/dfm b/dfm index 82d2f22..cc32790 100755 --- a/dfm +++ b/dfm @@ -138,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"