From b392dd372342edbd80bb05c9fffeea47da11d95a Mon Sep 17 00:00:00 2001 From: KlzXS Date: Tue, 13 Feb 2024 14:32:42 +0100 Subject: [PATCH] Added -- to all instances of cp, mv or rm dealing with user provided paths --- misc/musl/musl-static-ubuntu.sh | 4 ++-- misc/quitcd/quitcd.bash_sh_zsh | 2 +- misc/quitcd/quitcd.csh | 2 +- misc/quitcd/quitcd.elv | 2 +- misc/quitcd/quitcd.fish | 2 +- misc/quitcd/quitcd.nu | 2 +- plugins/.nmv | 8 ++++---- plugins/bulknew | 2 +- plugins/cbpaste-mac | 2 +- plugins/diffs | 2 +- plugins/dups | 6 +++--- plugins/finder | 2 +- plugins/fixname | 2 +- plugins/fzcd | 2 +- plugins/fzhist | 2 +- plugins/getplugs | 4 ++-- plugins/imgur | 2 +- plugins/imgview | 2 +- plugins/nbak | 4 ++-- plugins/nuke | 4 ++-- plugins/organize | 14 +++++++------- plugins/pdfread | 4 ++-- plugins/preview-tabbed | 2 +- plugins/preview-tui | 8 ++++---- src/nnn.c | 14 +++++++------- 25 files changed, 50 insertions(+), 50 deletions(-) diff --git a/misc/musl/musl-static-ubuntu.sh b/misc/musl/musl-static-ubuntu.sh index 987c636a..e9ceeb69 100755 --- a/misc/musl/musl-static-ubuntu.sh +++ b/misc/musl/musl-static-ubuntu.sh @@ -40,7 +40,7 @@ git checkout v0.3.2 if [ ! -d "./libs" ]; then mkdir libs else - rm -vf libs/* + rm -vf -- libs/* fi make CC=musl-gcc CFLAGS=-O3 LDFLAGS=-static all-static -j$(($(nproc)+1)) cp -v libcurses/libcurses.a libterminfo/libterminfo.a libs/ @@ -57,7 +57,7 @@ make CC=musl-gcc CFLAGS=-O3 LDFLAGS=-static -j$(($(nproc)+1)) # Compile nnn cd .. -[ -e "./netbsd-curses" ] || rm "$BIN" +[ -e "./netbsd-curses" ] || rm -- "$BIN" musl-gcc -O3 -DNORL -DNOMOUSE -std=c11 -Wall -Wextra -Wshadow -I./netbsd-curses/libcurses -I./musl-fts -o "$BIN" src/nnn.c -Wl,-Bsymbolic-functions -lpthread -L./netbsd-curses/libs -lcurses -lterminfo -static -L./musl-fts/.libs -lfts strip "$BIN" diff --git a/misc/quitcd/quitcd.bash_sh_zsh b/misc/quitcd/quitcd.bash_sh_zsh index 79e7ea4c..8be0dd6e 100644 --- a/misc/quitcd/quitcd.bash_sh_zsh +++ b/misc/quitcd/quitcd.bash_sh_zsh @@ -25,6 +25,6 @@ n () [ ! -f "$NNN_TMPFILE" ] || { . "$NNN_TMPFILE" - rm -f "$NNN_TMPFILE" > /dev/null + rm -f -- "$NNN_TMPFILE" > /dev/null } } diff --git a/misc/quitcd/quitcd.csh b/misc/quitcd/quitcd.csh index 72bd357d..d7e3f326 100644 --- a/misc/quitcd/quitcd.csh +++ b/misc/quitcd/quitcd.csh @@ -14,4 +14,4 @@ set NNN_TMPFILE=~/.config/nnn/.lastd # The backslash allows one to alias n to nnn if desired without making an # infinitely recursive alias -alias n '\nnn; source "$NNN_TMPFILE"; rm -f "$NNN_TMPFILE"' +alias n '\nnn; source "$NNN_TMPFILE"; rm -f -- "$NNN_TMPFILE"' diff --git a/misc/quitcd/quitcd.elv b/misc/quitcd/quitcd.elv index 95c47a6e..456ee870 100644 --- a/misc/quitcd/quitcd.elv +++ b/misc/quitcd/quitcd.elv @@ -36,6 +36,6 @@ fn n {|@a| if (path:is-regular $E:NNN_TMPFILE) { eval (slurp < $E:NNN_TMPFILE) - rm $E:NNN_TMPFILE + rm -- $E:NNN_TMPFILE } } diff --git a/misc/quitcd/quitcd.fish b/misc/quitcd/quitcd.fish index a8c3dc43..5dc3c71b 100644 --- a/misc/quitcd/quitcd.fish +++ b/misc/quitcd/quitcd.fish @@ -31,6 +31,6 @@ function n --wraps nnn --description 'support nnn quit and change directory' if test -e $NNN_TMPFILE source $NNN_TMPFILE - rm $NNN_TMPFILE + rm -- $NNN_TMPFILE end end diff --git a/misc/quitcd/quitcd.nu b/misc/quitcd/quitcd.nu index b00d21d1..c2211b65 100644 --- a/misc/quitcd/quitcd.nu +++ b/misc/quitcd/quitcd.nu @@ -30,7 +30,7 @@ export def --env n [ # Fix post-processing of nnn's given path that escapes its single quotes with POSIX syntax. let path = open $nnn_tmpfile | str substring 4..-1 | str replace --all `'\''` `'` - ^rm $nnn_tmpfile + ^rm -- $nnn_tmpfile cd $path } diff --git a/plugins/.nmv b/plugins/.nmv index eaebda6c..67abe166 100755 --- a/plugins/.nmv +++ b/plugins/.nmv @@ -32,7 +32,7 @@ case "$NNN_TRASH" in 2) RM_UTIL="gio trash" ;; *) - RM_UTIL="rm -ri" ;; + RM_UTIL="rm -ri --" ;; esac exit_status=0 @@ -64,7 +64,7 @@ lines=$(printf "%s\n" "$arr" | wc -l) width=${#lines} dst_file=$(mktemp "$TMPDIR/.nnnXXXXXX") -trap 'rm -f "$dst_file"' EXIT +trap 'rm -f -- "$dst_file"' EXIT printf "%s" "$arr" | awk '{printf("%'"${width}"'d %s\n", NR, $0)}' > "$dst_file" @@ -122,7 +122,7 @@ while read -r num name; do tmp="$tmp~$c" done - if mv "$name" "$tmp"; then + if mv -- "$name" "$tmp"; then if [ "$VERBOSE" -ne 0 ]; then printf "'%s' -> '%s'\n" "$name" "$tmp" fi @@ -142,7 +142,7 @@ while read -r num name; do if [ ! -d "$dir" ] && ! mkdir -p "$dir"; then printf "%s: failed to create directory tree %s\n" "$0" "$dir" > /dev/stderr exit_status=1 - elif ! mv -i "$src" "$name"; then + elif ! mv -i -- "$src" "$name"; then printf "%s: failed to rename %s to %s: %s\n" "$0" "$name" "$tmp" "$!" > /dev/stderr exit_status=1 else diff --git a/plugins/bulknew b/plugins/bulknew index 64331e47..77809618 100755 --- a/plugins/bulknew +++ b/plugins/bulknew @@ -29,4 +29,4 @@ $EDITOR "$tmpfile" sed "/^\//d" "$tmpfile" | xargs -n1 -I{} sh -c "$cmd" -rm "$tmpfile" +rm -- "$tmpfile" diff --git a/plugins/cbpaste-mac b/plugins/cbpaste-mac index 51af9e29..5edf9c62 100755 --- a/plugins/cbpaste-mac +++ b/plugins/cbpaste-mac @@ -21,4 +21,4 @@ fs=($( osascript -e "use framework \"Foundation\" pb's readObjectsForClasses:[NSURL] options:[] (result's valueForKey:\"path\") as list as text" )) -cp -R "${fs[@]}" "$2/" \ No newline at end of file +cp -R -- "${fs[@]}" "$2/" diff --git a/plugins/diffs b/plugins/diffs index 0464781b..16adc4b8 100755 --- a/plugins/diffs +++ b/plugins/diffs @@ -25,7 +25,7 @@ dirdiff() { ls -A1 "$1" > "$dir1" ls -A1 "$2" > "$dir2" $diffcmd "$dir1" "$dir2" - rm "$dir1" "$dir2" + rm -- "$dir1" "$dir2" } if [ -s "$selection" ]; then diff --git a/plugins/dups b/plugins/dups index 27c1807f..d402367f 100755 --- a/plugins/dups +++ b/plugins/dups @@ -58,13 +58,13 @@ read -r force if [ "$force" = "f" ]; then #shellcheck disable=SC2016 - sed -e "$sedcmd" "$tmpfile" | tr '\n' '\0' | xargs -0 -r sh -c 'rm -f "$0" "$@" "$TMPDIR/finderbms" printf "%s\n" "$fexpr" >> "$TMPDIR/finderbms" - mv "$TMPDIR/finderbms" "$NNN_FINDHIST" + mv -- "$TMPDIR/finderbms" "$NNN_FINDHIST" fi fi diff --git a/plugins/fixname b/plugins/fixname index 40471520..2b0ec1b9 100755 --- a/plugins/fixname +++ b/plugins/fixname @@ -65,7 +65,7 @@ for i in "${targets[@]}"; do if [ -e "$(cleanup "$i")" ]; then tmp='_' fi - mv "$i" "$tmp$(cleanup "$i")"; + mv -- "$i" "$tmp$(cleanup "$i")"; fi done diff --git a/plugins/fzcd b/plugins/fzcd index 125092cb..35fae7e5 100755 --- a/plugins/fzcd +++ b/plugins/fzcd @@ -60,7 +60,7 @@ if [ -n "$LIST" ]; then # Alternative for 'fd' # sel=$(xargs -d '\n' < "$tmpfile" fd . | fzf --delimiter / --tiebreak=begin --info=hidden) - rm "$tmpfile" + rm -- "$tmpfile" else printf "find missing" read -r _ diff --git a/plugins/fzhist b/plugins/fzhist index bdfd9296..de10c2a6 100755 --- a/plugins/fzhist +++ b/plugins/fzhist @@ -46,7 +46,7 @@ if [ -n "$entry" ]; then $SHELL -c "$(cat "$tmpfile")" fi - rm "$tmpfile" + rm -- "$tmpfile" printf "Press any key to exit" read -r _ diff --git a/plugins/getplugs b/plugins/getplugs index 361a605f..30dbf7b0 100755 --- a/plugins/getplugs +++ b/plugins/getplugs @@ -24,7 +24,7 @@ prompt () { if [ "$operation" = "m" ]; then op="merge" elif [ "$operation" = "o" ]; then - op="cp -vRf" + op="cp -vRf --" else op="true" fi @@ -62,7 +62,7 @@ for f in $(find . -maxdepth 1 \( ! -iname "." ! -iname "*.md" \)); do $op "$f" ../../plugins/ fi else - cp -vRf "$f" ../../plugins/ + cp -vRf -- "$f" ../../plugins/ fi done cd ../.. || exit 1 diff --git a/plugins/imgur b/plugins/imgur index 16d21bcd..e5981fc1 100755 --- a/plugins/imgur +++ b/plugins/imgur @@ -583,7 +583,7 @@ for upload_file in "${upload_files[@]}"; do # delete file if configured if [ "${keep_file}" = "false" ] && [ -z "${1}" ]; then echo "Deleting temp file ${file_dir}/${img_file}" - rm -rf "${img_file}" + rm -rf -- "${img_file}" fi echo "" diff --git a/plugins/imgview b/plugins/imgview index d8cc247a..03375113 100755 --- a/plugins/imgview +++ b/plugins/imgview @@ -54,7 +54,7 @@ make_thumbs() { done for file in "$NNN_PREVIEWDIR$dir"/*; do filename="$(basename "$file" .jpg)" - [ ! -e "$dir/$filename" ] && rm "$file" 2>/dev/null + [ ! -e "$dir/$filename" ] && rm -- "$file" 2>/dev/null done } diff --git a/plugins/nbak b/plugins/nbak index f9cb6449..9950026d 100755 --- a/plugins/nbak +++ b/plugins/nbak @@ -34,7 +34,7 @@ fi cd "$tempdir/$outdir" || exit 1 # Backing up config dir content -cp -r "$configdir" . || exit 1 +cp -r -- "$configdir" . || exit 1 # Environment config env | sed "s/'/'\\\\''/" |\ @@ -72,4 +72,4 @@ printf "Saving as '%s' ... " "$workdir/$outfile" tar caf "$workdir/$outfile" "$outdir" && echo "Done" || echo "Failed" -cd "$workdir" && rm -rf "$tempdir" +cd "$workdir" && rm -rf -- "$tempdir" diff --git a/plugins/nuke b/plugins/nuke index b3eafc89..d6bb49b4 100755 --- a/plugins/nuke +++ b/plugins/nuke @@ -277,7 +277,7 @@ listimages() { load_dir() { abspath "$2" tmp="${TMPDIR:-/tmp}/nuke_$$" - trap 'rm -f $tmp' EXIT + trap 'rm -f -- "$tmp"' EXIT count="$(listimages "$abs_target" | grep -a -m 1 -ZznF "$abs_target" | cut -d: -f1)" if [ -n "$count" ]; then @@ -402,7 +402,7 @@ handle_multimedia() { # "${FPATH}"; # then # convert -- "${preview_png}" "${IMAGE_CACHE_PATH}" \ - # && rm "${preview_png}" \ + # && rm -- "${preview_png}" \ # && exit 6 # else # exit 1 diff --git a/plugins/organize b/plugins/organize index fb70aaff..81cc9df4 100755 --- a/plugins/organize +++ b/plugins/organize @@ -13,36 +13,36 @@ organize() { case "$(file -biL "$1")" in *video*) [ ! -d "Videos" ] && mkdir "Videos" - mv "$1" "Videos/$1" + mv -- "$1" "Videos/$1" printf "Moved %s to Videos\n" "$1" ;; *audio*) [ ! -d "Audio" ] && mkdir "Audio" - mv "$1" "Audio/$1" + mv -- "$1" "Audio/$1" printf "Moved %s to Audio\n" "$1" ;; *image*) [ ! -d "Images" ] && mkdir "Images" - mv "$1" "Images/$1" + mv -- "$1" "Images/$1" printf "Moved %s to Images\n" "$1" ;; *pdf*|*document*|*epub*|*djvu*|*cb*) [ ! -d "Documents" ] && mkdir "Documents" - mv "$1" "Documents/$1" + mv -- "$1" "Documents/$1" printf "Moved %s to Documents\n" "$1" ;; *text*) [ ! -d "Plaintext" ] && mkdir "Plaintext" - mv "$1" "Plaintext/$1" + mv -- "$1" "Plaintext/$1" printf "Moved %s to Plaintext\n" "$1" ;; *tar*|*xz*|*compress*|*7z*|*rar*|*zip*) [ ! -d "Archives" ] && mkdir "Archives" - mv "$1" "Archives/$1" + mv -- "$1" "Archives/$1" printf "Moved %s to Archives\n" "$1" ;; *binary*) [ ! -d "Binaries" ] && mkdir "Binaries" - mv "$1" "Binaries/$1" + mv -- "$1" "Binaries/$1" printf "Moved %s to Binaries\n" "$1" ;; esac } diff --git a/plugins/pdfread b/plugins/pdfread index 1e889be1..9f657289 100755 --- a/plugins/pdfread +++ b/plugins/pdfread @@ -15,7 +15,7 @@ if [ -n "$1" ]; then pico2wave -w "$tmpf".wav -l en-GB "$(tr '\n' ' ' < "$tmpf".txt)" - rm "$tmpf".txt + rm -- "$tmpf".txt else pico2wave -w "$tmpf".wav -l en-GB "$(tr '\n' ' ' < "$1")" fi @@ -26,5 +26,5 @@ if [ -n "$1" ]; then # flat read but better quality # play -qV0 "$tmpf".wav treble 2 gain -l 2 - rm "$tmpf".wav + rm -- "$tmpf".wav fi diff --git a/plugins/preview-tabbed b/plugins/preview-tabbed index 8f454ce8..68d8d1ab 100755 --- a/plugins/preview-tabbed +++ b/plugins/preview-tabbed @@ -92,7 +92,7 @@ start_tabbed () { read -r XID < "$FIFO" - rm "$FIFO" + rm -- "$FIFO" } get_viewer_pid () { diff --git a/plugins/preview-tui b/plugins/preview-tui index 467d441d..f813ca54 100755 --- a/plugins/preview-tui +++ b/plugins/preview-tui @@ -259,7 +259,7 @@ fifo_pager() { fi ) - rm "$FIFOPATH" + rm -- "$FIFOPATH" } # Binary file: show file info inside the pager @@ -423,7 +423,7 @@ generate_preview() { fi ;; office) libreoffice --convert-to jpg "$3" --outdir "$NNN_PREVIEWDIR/${3%/*}" filename="$(printf "%s" "${3##*/}" | cut -d. -f1)" - mv "$NNN_PREVIEWDIR/${3%/*}/$filename.jpg" "$NNN_PREVIEWDIR/$3.jpg" ;; + mv -- "$NNN_PREVIEWDIR/${3%/*}/$filename.jpg" "$NNN_PREVIEWDIR/$3.jpg" ;; pdf) pdftoppm -jpeg -f 1 -singlefile "$3" "$NNN_PREVIEWDIR/$3" ;; djvu) ddjvu -format=ppm -page=1 "$3" "$NNN_PREVIEWDIR/$3.jpg" ;; video) video_preview "$1" "$2" "$3" && return ;; @@ -467,7 +467,7 @@ video_preview() { if [ -n "$NNN_PREVIEWVIDEO" ]; then mpv --no-config --really-quiet --vo="$NNN_PREVIEWVIDEO" --profile=sw-fast --loop-file --no-audio "$4" "$3" & else - ffmpegthumbnailer -m -s0 -i "$3" -o "$NNN_PREVIEWDIR/$3.jpg" || rm "$NNN_PREVIEWDIR/$3.jpg" & + ffmpegthumbnailer -m -s0 -i "$3" -o "$NNN_PREVIEWDIR/$3.jpg" || rm -- "$NNN_PREVIEWDIR/$3.jpg" & fi printf "%s" "$!" > "$PREVIEWPID" } @@ -517,7 +517,7 @@ if [ "$PREVIEW_MODE" -eq 1 ] 2>/dev/null; then printf "%s" "$!" > "$FIFOPID" printf "%s" "$PWD/$1" > "$CURSEL" trap 'winch_handler' WINCH - trap 'rm "$PREVIEWPID" "$CURSEL" "$FIFO_UEBERZUG" "$FIFOPID" "$POSOFFSET" 2>/dev/null' INT HUP EXIT + trap 'rm -- "$PREVIEWPID" "$CURSEL" "$FIFO_UEBERZUG" "$FIFOPID" "$POSOFFSET" 2>/dev/null' INT HUP EXIT while kill -s 0 $WAITPID; do wait $WAITPID 2>/dev/null done diff --git a/src/nnn.c b/src/nnn.c index 6792d503..850c9b64 100644 --- a/src/nnn.c +++ b/src/nnn.c @@ -589,7 +589,7 @@ static char * const utils[] = { ".nmv", "trash-put", "gio trash", - "rm -rf", + "rm -rf --", "archivemount", }; @@ -743,8 +743,8 @@ static const char * const envs[] = { #define PROGRESS_CP "cpg -giRp" #define PROGRESS_MV "mvg -gi" -static char cp[sizeof PROGRESS_CP] = "cp -iRp"; -static char mv[sizeof PROGRESS_MV] = "mv -i"; +static char cp[sizeof PROGRESS_CP] = "cp -iRp --"; +static char mv[sizeof PROGRESS_MV] = "mv -i --"; /* Archive commands */ static char * const archive_cmd[] = {"atool -a", "bsdtar -acvf", "zip -r", "tar -acvf"}; @@ -2555,7 +2555,7 @@ static bool rmmulstr(char *buf, bool use_trash) return FALSE; if (!use_trash) - snprintf(buf, CMD_LEN_MAX, "xargs -0 sh -c 'rm -%cr \"$0\" \"$@\" < /dev/tty' < %s", + snprintf(buf, CMD_LEN_MAX, "xargs -0 sh -c 'rm -%cr -- \"$0\" \"$@\" < /dev/tty' < %s", r, selpath); else snprintf(buf, CMD_LEN_MAX, "xargs -0 %s < %s", @@ -2575,7 +2575,7 @@ static bool xrm(char * const fpath, bool use_trash) char rm_opts[] = "-ir"; rm_opts[1] = r; - spawn("rm", rm_opts, fpath, NULL, F_NORMAL | F_CHKRTN); + spawn("rm", rm_opts, "--", fpath, F_NORMAL | F_CHKRTN); } else spawn(utils[(g_state.trash == 1) ? UTIL_TRASH_CLI : UTIL_GIO_TRASH], fpath, NULL, NULL, F_NORMAL | F_MULTI); @@ -2728,7 +2728,7 @@ static bool batch_rename(void) bool dir = FALSE, ret = FALSE; char foriginal[TMP_LEN_MAX] = {0}; static const char batchrenamecmd[] = "paste -d'\n' %s %s | "SED" 'N; /^\\(.*\\)\\n\\1$/!p;d' | " - "tr '\n' '\\0' | xargs -0 -n2 sh -c 'mv -i \"$0\" \"$@\" <" + "tr '\n' '\\0' | xargs -0 -n2 sh -c 'mv -i -- \"$0\" \"$@\" <" " /dev/tty'"; char buf[sizeof(batchrenamecmd) + (PATH_MAX << 1)]; int i = get_cur_or_sel(); @@ -7861,7 +7861,7 @@ nochange: if (sel == SEL_RENAME) { /* Rename the file */ if (ret == 'd') - spawn("cp -rp", pdents[cur].name, tmp, NULL, F_SILENT); + spawn("cp -rp --", pdents[cur].name, tmp, NULL, F_SILENT); else if (rename(pdents[cur].name, tmp) != 0) { printwarn(&presel); goto nochange;