Just hoping someone might be able help me with the use of sed within a script.
Using nsxiv
in thumbnail mode -t
, I have functions set up in my ~/.config/nsxiv/exec/key-handler
to perform certain tasks.
One such function is to copy the selected file(s) to another location. This function relies on dmenu
for the input of the new destdir
.
Key-handler:
#!/bin/sh
while read file
do
case "$1" in
# Copy file to another location
"c")
[ -z "$destdir" ] &&
destdir="$(sed "s/\s.*#.*$//;/^\s*$/d" ${XDG_CONFIG_HOME:-$HOME/.config}/shell/bm-dirs |
awk '{print $2}' |
dmenu -fn 'CodeNewRomanNerdFont:style=Normal:pixelsize=14:antialias=true' \
-nb '#2d2d2d' \
-nf '#c0c5ce' \
-sb '#5fb3b3' \
-sf '#000000' \
-l 20 \
-i -p "Copy file(s) to where?" |
sed "s|~|$HOME|g")"
[ ! -d "$destdir" ] && notify-send -t 5000 -a "$destdir" "Not a directory, cancelled" && exit
cp "$file" "$destdir" && notify-send -t 5000 -a "Copied To" "$destdir" &
;;
esac
done
This works as intended, but when nxsiv
is run from a terminal I see the following message after execution
sed: 1: "s/\s.*#.*$//;/^\s*$/d": RE error: trailing backslash (\)
Of course I tried simply removing the two trailing backslashes which eliminates the message, but this resulted in dmenu
adding an extra line under it's input field.
I'm simply curious to know how I would write it so that the shell wouldn't complain?
Also, if anyone knows a neater way to define my dmenu
variables only once I'd be glad to know how. It seems using a ~/.dmenurc
doesn't really work anymore 😕