sistema_progs

Programas para customizar o meu entorno de traballo nos meus equipos persoais
Log | Files | Refs

renamer (1154B)


      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