Skip to content

Commit

Permalink
made file names with brackets always work
Browse files Browse the repository at this point in the history
  • Loading branch information
amarz45 committed Jul 13, 2022
1 parent 5478d74 commit 813b89a
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions dfm
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,21 @@ main() {
}

prompt_base() {
[ -z $length ] && length=10
[ -z $length ] && length=10

if [ "$case_sensitivity" = "sensitive" ]; then
menu="dmenu -l $length" greps="grep"
menu="dmenu -l $length" grep="grep"
backtrack() { sed 's|\(.*/'$sel'[^/]*\).*|\1|'; }
else
menu="dmenu -i -l $length" greps="grep -i"
menu="dmenu -i -l $length" grep="grep -i"
backtrack() { perl -pe 's|(.*/'$sel'[^/]*).*|$1|i'; }
fi

{ [ "$path" = "full" ] && prompt() { p="$target"; }; } ||
{ prompt() { p="`echo "$target" | sed 's|^'"$HOME"'|~|'`"; }; }

truepath() { sh -c "realpath -s "$sel""; }
slash() { echo "$target/$sel" | rev | cut -b 1-2; }
check() { file -E "$@" | grep "(No such file or directory)$"; }
fullcmd() { echo "$target" | sed -e "s/'/'\\\\''/g;s/\(.*\)/'\1'/" | cmd ; exit 0; }

Expand All @@ -36,10 +37,12 @@ prompt_base() {
ec=$? ; [ "$ec" -ne 0 ] && exit $ec

if [ `echo "$sel" | wc -l` -eq 1 ]; then
if [ ! -e "$target/$sel" -a $(echo "$target" | $greps "$(sh -c "echo "$sel"")" | wc -l) -eq 1 ]; then
if [ -e "$target/$sel" -a "`slash`" != "//" ]; then
newt="`realpath -s "$target/$sel"`"
elif [ ! -e "$target/$sel" -a $(echo "$target" | $grep "$(sh -c "echo "$sel"")" | wc -l) -eq 1 ]; then
{ [ ! -e "`truepath`" ] && newt="`echo "$target" | backtrack`"; } ||
{ newt="`truepath`"; }
elif [ -e "`truepath`" ] && [ ! -e "$target/$sel" -o "`echo "$target/$sel" | rev | cut -b 1-2`" = "//" ]; then
elif [ -e "`truepath`" ] && [ ! -e "$target/$sel" -o "`slash`" = "//" ]; then
newt="`truepath`"
else
newt="`realpath -s "$target/$sel"`"
Expand All @@ -58,8 +61,10 @@ prompt_base() {
{ target=`ls -d "$PWD"/$sel` fullcmd; }
elif [ `echo "$target" | wc -l` -eq 1 -a `check "$target" | wc -l` -eq 1 ]; then
target="$PWD"
else
elif [ `echo "$target" | wc -l` -gt 1 ]; then
target=`echo "$target" | sed 's|^|'"$PWD"/'|'` fullcmd
else
fullcmd
fi
else
PWD="$target"
Expand Down

0 comments on commit 813b89a

Please sign in to comment.