Skip to content

Instantly share code, notes, and snippets.

@KyonLi
Last active June 16, 2024 05:42
Show Gist options
  • Select an option

  • Save KyonLi/13519d7f9b06046723c2de3da88c5bfc to your computer and use it in GitHub Desktop.

Select an option

Save KyonLi/13519d7f9b06046723c2de3da88c5bfc to your computer and use it in GitHub Desktop.

Revisions

  1. KyonLi revised this gist Jun 16, 2024. 1 changed file with 6 additions and 6 deletions.
    12 changes: 6 additions & 6 deletions remove_prefix.sh
    Original file line number Diff line number Diff line change
    @@ -5,13 +5,13 @@ prefix="*-"
    shopt -s nullglob

    rename(){
    local files=( $prefix* )
    for i in ${!files[*]}
    local files=( $prefix* )
    for i in ${!files[*]}
    do
    local file=${files[i]}
    mv "$file" "${file#$prefix}"
    echo "$file${file#$prefix}"
    done
    local file=${files[i]}
    mv "$file" "${file#$prefix}"
    echo "$file${file#$prefix}"
    done
    }

    rename
  2. KyonLi revised this gist Jun 16, 2024. 1 changed file with 17 additions and 0 deletions.
    17 changes: 17 additions & 0 deletions remove_prefix.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,17 @@
    #!/bin/bash

    prefix="*-"

    shopt -s nullglob

    rename(){
    local files=( $prefix* )
    for i in ${!files[*]}
    do
    local file=${files[i]}
    mv "$file" "${file#$prefix}"
    echo "$file${file#$prefix}"
    done
    }

    rename
  3. KyonLi created this gist Jan 30, 2024.
    21 changes: 21 additions & 0 deletions rename_index.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,21 @@
    #!/bin/bash

    ext=jpg

    shopt -s nullglob
    OLDIFS=$IFS

    rename(){
    IFS=$'\n'
    local arr=( $(ls -v *.$ext) )
    IFS=$OLDIFS

    for i in ${!arr[*]}
    do
    local filename=$(printf "%03d" $(($i+1)))
    mv "${arr[i]}" "${filename}.${ext}"
    echo "${arr[i]}${filename}.${ext}"
    done
    }

    rename
    20 changes: 20 additions & 0 deletions rename_subtitle.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,20 @@
    #!/bin/bash

    vid_ext=mkv
    sub_ext=ass
    after_sub_ext=sc.ass

    shopt -s nullglob

    rename(){
    local vid_arr=( *.$vid_ext )
    local sub_arr=( *.$sub_ext )
    for i in ${!vid_arr[*]}
    do
    local filename=${vid_arr[i]%.*}
    mv "${sub_arr[i]}" "${filename}.${after_sub_ext}"
    echo "${sub_arr[i]}${filename}.${after_sub_ext}"
    done
    }

    rename