annotate bin/putcrc @ 677:b95069a1f664

[irbrc] Disable autocomplete It's kinda slow and moves things around.
author nanaya <me@nanaya.pro>
date Fri, 08 Apr 2022 13:47:15 +0900
parents 08d5f6023998
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
4
94ee419ad047 Added bin-ec - a collection of scripts.
Edho Prima Arief <me@myconan.net>
parents:
diff changeset
1 #!/bin/sh
94ee419ad047 Added bin-ec - a collection of scripts.
Edho Prima Arief <me@myconan.net>
parents:
diff changeset
2 safe_path()
94ee419ad047 Added bin-ec - a collection of scripts.
Edho Prima Arief <me@myconan.net>
parents:
diff changeset
3 {
94ee419ad047 Added bin-ec - a collection of scripts.
Edho Prima Arief <me@myconan.net>
parents:
diff changeset
4 # It all depends on the first character.
94ee419ad047 Added bin-ec - a collection of scripts.
Edho Prima Arief <me@myconan.net>
parents:
diff changeset
5 __start=$(printf "%s" "$*" | cut -c 1)
94ee419ad047 Added bin-ec - a collection of scripts.
Edho Prima Arief <me@myconan.net>
parents:
diff changeset
6 __path=
94ee419ad047 Added bin-ec - a collection of scripts.
Edho Prima Arief <me@myconan.net>
parents:
diff changeset
7 case "${__start}" in
94ee419ad047 Added bin-ec - a collection of scripts.
Edho Prima Arief <me@myconan.net>
parents:
diff changeset
8 .|/) __path="$*";; # . and / is safe. No change.
94ee419ad047 Added bin-ec - a collection of scripts.
Edho Prima Arief <me@myconan.net>
parents:
diff changeset
9 *) __path="./$*";; # Anything else must be prefixed with ./
94ee419ad047 Added bin-ec - a collection of scripts.
Edho Prima Arief <me@myconan.net>
parents:
diff changeset
10 esac
94ee419ad047 Added bin-ec - a collection of scripts.
Edho Prima Arief <me@myconan.net>
parents:
diff changeset
11 printf "%s" "${__path}" # Return.
94ee419ad047 Added bin-ec - a collection of scripts.
Edho Prima Arief <me@myconan.net>
parents:
diff changeset
12 }
94ee419ad047 Added bin-ec - a collection of scripts.
Edho Prima Arief <me@myconan.net>
parents:
diff changeset
13
94ee419ad047 Added bin-ec - a collection of scripts.
Edho Prima Arief <me@myconan.net>
parents:
diff changeset
14 if [ "$#" -lt 1 ]; then
94ee419ad047 Added bin-ec - a collection of scripts.
Edho Prima Arief <me@myconan.net>
parents:
diff changeset
15 cat <<EOF
94ee419ad047 Added bin-ec - a collection of scripts.
Edho Prima Arief <me@myconan.net>
parents:
diff changeset
16 Usage: $(basename "/$0") file1 file2 ... fileN
94ee419ad047 Added bin-ec - a collection of scripts.
Edho Prima Arief <me@myconan.net>
parents:
diff changeset
17 EOF
94ee419ad047 Added bin-ec - a collection of scripts.
Edho Prima Arief <me@myconan.net>
parents:
diff changeset
18 exit 1
94ee419ad047 Added bin-ec - a collection of scripts.
Edho Prima Arief <me@myconan.net>
parents:
diff changeset
19 fi
94ee419ad047 Added bin-ec - a collection of scripts.
Edho Prima Arief <me@myconan.net>
parents:
diff changeset
20
94ee419ad047 Added bin-ec - a collection of scripts.
Edho Prima Arief <me@myconan.net>
parents:
diff changeset
21 for file in "$@"; do
94ee419ad047 Added bin-ec - a collection of scripts.
Edho Prima Arief <me@myconan.net>
parents:
diff changeset
22 if [ -f "${file}" ] && [ -r "${file}" ] && [ -n "$(printf "%s\n" "${file}" | sed -e 's/.*[A-F0-9]\{8\}.*//')" ]; then
94ee419ad047 Added bin-ec - a collection of scripts.
Edho Prima Arief <me@myconan.net>
parents:
diff changeset
23 filename="$(basename "$(safe_path "${file}")")"
94ee419ad047 Added bin-ec - a collection of scripts.
Edho Prima Arief <me@myconan.net>
parents:
diff changeset
24 dirname="$(dirname "$(safe_path "${file}")")"
94ee419ad047 Added bin-ec - a collection of scripts.
Edho Prima Arief <me@myconan.net>
parents:
diff changeset
25 myfile="$(printf "%s\n" "${filename%.*}" | sed -e 's/\([^]]\)$/\1 /')"
94ee419ad047 Added bin-ec - a collection of scripts.
Edho Prima Arief <me@myconan.net>
parents:
diff changeset
26 myext="${filename##*.}"; if [ "${myext}" = "${filename}" ]; then myext=""; else myext=".${myext}"; fi
79
08d5f6023998 Replace checksum calculator with python version.
Edho Prima Arief <me@myconan.net>
parents: 4
diff changeset
27 crc=$(cek.py "$(safe_path "${file}")" | tail -1 | sed -e 's/.*\([A-F0-9]\{8\}\)$/\1/')
4
94ee419ad047 Added bin-ec - a collection of scripts.
Edho Prima Arief <me@myconan.net>
parents:
diff changeset
28 mv -- "${file}" "${dirname}/${myfile}[${crc}]${myext}" && printf "%s => %s\n" "${file}" "${myfile}[${crc}]${myext}"
94ee419ad047 Added bin-ec - a collection of scripts.
Edho Prima Arief <me@myconan.net>
parents:
diff changeset
29 else
94ee419ad047 Added bin-ec - a collection of scripts.
Edho Prima Arief <me@myconan.net>
parents:
diff changeset
30 printf "%s\n" "${file} is not a file or unreadable"
94ee419ad047 Added bin-ec - a collection of scripts.
Edho Prima Arief <me@myconan.net>
parents:
diff changeset
31 fi
94ee419ad047 Added bin-ec - a collection of scripts.
Edho Prima Arief <me@myconan.net>
parents:
diff changeset
32 done