"Fossies" - the Fresh Open Source Software Archive

Member "nnn-4.2/plugins/renamer" (21 Jul 2021, 1154 Bytes) of package /linux/misc/nnn-v4.2.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Bash source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. See also the latest Fossies "Diffs" side-by-side code changes report for "renamer": v4.1.1_vs_v4.2.

    1 #!/usr/bin/env sh
    2 
    3 # Description: Batch rename selection or current directory with qmv or vidir
    4 #
    5 # Notes:
    6 #   - Try to mimic current batch rename functionality but with correct
    7 #     handling of edge cases by qmv or vidir.
    8 #   - Qmv opens with hidden files if no selection is used. Selected
    9 #     directories are shown.
   10 #   - Vidir don't show directories nor hidden files.
   11 #
   12 # Shell: POSIX compliant
   13 # Author: José Neder
   14 
   15 selection=${NNN_SEL:-${XDG_CONFIG_HOME:-$HOME/.config}/nnn/.selection}
   16 
   17 if type qmv >/dev/null 2>&1; then
   18     batchrenamesel="qmv -fdo -da"
   19     batchrename="qmv -fdo -a"
   20 elif type vidir >/dev/null 2>&1; then
   21     batchrenamesel="vidir"
   22     batchrename="vidir"
   23 else
   24     printf "there is not batchrename program installed."
   25     exit
   26 fi
   27 
   28 if [ -s "$selection" ]; then
   29     printf "rename selection? "
   30     read -r resp
   31 fi
   32 
   33 if [ "$resp" = "y" ]; then
   34     # -o flag is necessary for interactive editors
   35     xargs -o -0 $batchrenamesel < "$selection"
   36 
   37     # Clear selection
   38     if [ -p "$NNN_PIPE" ]; then
   39         printf "-" > "$NNN_PIPE"
   40     fi
   41 elif [ ! "$(LC_ALL=C ls -a)" = ".
   42 .." ]; then
   43     # On older systems that don't have ls -A
   44     $batchrename
   45 fi