Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option to open shell. #8

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 11 additions & 11 deletions dfm
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand All @@ -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

Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down