From b43d99f9a1aba9140e48c556af3dc245b74792c3 Mon Sep 17 00:00:00 2001 From: tastytea Date: Fri, 18 Mar 2022 23:11:27 +0100 Subject: [PATCH] Zsh: Turn machklein.sh into a function and name it mksmol --- .config/zsh/.zaliases | 2 ++ .config/zsh/functions.zsh | 17 ++++++++++++++++- bin/machklein.sh | 12 ------------ 3 files changed, 18 insertions(+), 13 deletions(-) delete mode 100755 bin/machklein.sh diff --git a/.config/zsh/.zaliases b/.config/zsh/.zaliases index 86887ea..3b6c6f0 100644 --- a/.config/zsh/.zaliases +++ b/.config/zsh/.zaliases @@ -80,6 +80,8 @@ alias wget_leech='wget --no-directories --page-requisites --span-hosts' alias cat='cat-highlight' +alias machklein='mksmol' + # OS specific settings. case $(lsb_release -i -s 2> /dev/null) in Gentoo) diff --git a/.config/zsh/functions.zsh b/.config/zsh/functions.zsh index 15deec3..10b1b70 100644 --- a/.config/zsh/functions.zsh +++ b/.config/zsh/functions.zsh @@ -1,5 +1,5 @@ #!/bin/zsh -# Various functions, to be sourced. +# Various small functions # Get backtrace from gdb. function gdb_get_backtrace() @@ -51,3 +51,18 @@ function cat-highlight() \cat $@ fi } + +# Makes all files in DIR lower case. Works with Non-ASCII characters. +function mksmol() +{ + if [[ ${ARGC} -ne 1 ]]; then + echo "usage: ${0} DIR" >&2 + return 1 + fi + + local dir="${1}" + for file in "${dir}"/*; do + newfile="${file:l}" + [[ "${file}" != "${newfile}" ]] && mv "${file}" "${newfile}" || : + done +} diff --git a/bin/machklein.sh b/bin/machklein.sh deleted file mode 100755 index 545e122..0000000 --- a/bin/machklein.sh +++ /dev/null @@ -1,12 +0,0 @@ -#!/bin/zsh - -if [[ -z "${1}" ]]; then - echo "usage: ${0} DIR" >&2 - exit 1 -fi -dir="${1}" - -for file in "${dir}"/*; do - newfile="${file:l}" - [[ "${file}" != "${newfile}" ]] && mv "${file}" "${newfile}" || echo -n -done