Mirrored from GitHub

git clone https://github.com/christc4/shell-scripts.git

Jump to:
ONE-LINER.txt
batch-image-convert.sh
cn-char-lookup.sh
fuzzy-edit1.sh
fuzzy-edit2.sh
json-generate.sh
screenshot-to-clipboard.sh


ONE-LINER.txt

1REPLACE 'SPACES' in filenames with 'UNDERSCORE'
2
3find . -name '* *' | while IFS= read -r f; do mv "$f" "$(echo "$f" | tr ' ' '_')"; done
4
5Convert UPPERCASE filenames to LOWERCASE
6
7for file in *; do mv "$file" "$(echo "$file" | tr '[:upper:]' '[:lower:]')"; done
8
9Batch file RENAME
10
11find . -type f -name 'index.md' -execdir mv '{}' i.md \;
12
13Get file SIZE
14
15du -sk * | sort -nr | awk '{print $1/1024 " MB\t" $2}'
16
17Fuzzy CD
18
19cd $(find /var/www/werc/sites -type d \( -name .git -prune \) -o \( -type d -print \) | fzf) && clear
20
21SCREEENSHOT to CLIPBOARD
22
23import png:- | xclip -selection c -t image/png
24
25SHUFFLE images
26
27find . -type f | shuf | nsxiv -ai

batch-image-convert.sh

1#!/bin/sh
2
3convert_webp_to_avif() {
4    input_file="$1"
5    output_file="${input_file%.webp}.avif"
6    convert "$input_file" "$output_file"
7}
8
9find . -type f -name '*.webp' -exec sh -c '
10    for file; do
11	output_file="${file%.webp}.avif"
12	convert "$file" "$output_file"
13    done
14' sh {} +
15
16echo "Conversion complete!"

cn-char-lookup.sh

1#!/bin/sh
2
3hanzi="$1"
4url="https://tatoeba.org/en/sentences/search?from=cmn&query=$chinese_character&to=eng"
5
6if [ -z "$BROWSER" ]; then
7    echo "$BROWSER not set"
8    exit 1
9fi
10
11if [ $# -ne 1 ]; then
12    echo "$0 <hanzi>"
13    exit 1
14fi
15

fuzzy-edit1.sh

1#!/bin/sh
2
3clear &&
4$EDITOR "$(find /home -type d -name '.git' -prune -o -type f \
5-not -name '*.webp' \
6-not -name '*.webm' \
7-not -name '*.pdf' \
8-not -name '*.jpg' \
9-not -name '*.jpeg' \
10-not -name '*.gif' \
11-not -name '*.png' \
12-not -name '*.mp4' -print | fzf --info=inline --preview 'cat {}')"

fuzzy-edit2.sh

1#!/bin/sh
2
3clear &&
4$EDITOR "$(fd --type f \
5    --exclude '*.{png,jpg,jpeg,gif,webp,avif,mp4,mkv,avi,mov,flv,wmv,webm,pdf,swp,swo}' \
6    . /home | fzf --info=inline --preview 'bat --style=numbers --color=always --line-range :500 {}')"

json-generate.sh

1#!/bin/sh
2
3echo "[" > s.json
4
5find . -type f -name "*.md" | sed 's|^\./||; s|\.md$||' | awk '{
6  if (NR == 1) {
7    printf "  \"%s\"", $0
8  } else {
9    printf ",\n  \"%s\"", $0
10  }
11} END {
12  print "\n]"
13}' >> s.json

screenshot-to-clipboard.sh

1#!/bin/sh
2
3import png:- | xclip -selection c -t image/png