Welcome to Vifm Q&A, where you can ask questions about using Vifm. Registration is optional, anonymous posts are moderated. E-mail and GitHub logins are enabled.
0 votes
in vifm by

How can I add automatic increasing numbering to the beginning or end of a list of selected files/folders?

thanks

1 Answer

0 votes
by

I can't think of a way to do that without using Vim via :rename. There you can add numbers (e.g., :%s/^/1/), select a column of numbers visually with Ctrl-V and do gCtrl-A.

by
edited by

if this could help:

create a script with the name rename_with_increment_prefix.sh:

#!/bin/bash

# will rename
# 123.jpg, "live is life.txt", some_script.sh
# to
# 1_123.jpg, 2_live is life.txt, 3_some_script.sh, etc....

i=1
for f in "$@"; do
  # Extract the directory, filename, and extension
  dir_name=$(dirname "$f")
  base_name=$(basename "$f")

  # Construct the new file name with number prefix and original name
  new_name="$dir_name/${i}_${base_name}"

  echo "Renaming: $f to $new_name"

  # Check if the new file name already exists
  if [ -e "$new_name" ]; then
  echo "Error: $new_name already exists."
  exit 1
  fi

  # Rename the file
  mv "$f" "$new_name"

  # Increment the counter
  i=$((i+1))
done

then write this line in vifmrc:

command! renameWithIncrementPrefix $VIFM_TERMINAL '/path/of/your/script/rename_with_increment_prefix.sh %f %i'

restart vifm

select a few dir or files

call the command:

:renameWithIncrementPrefix

Note: after renaming it is not possible to undo

If you would like to make a bug report or feature request consider using GitHub, SourceForge or e-mail. Posting such things here is acceptable, but this is not a perfect place for them.
...