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

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

batch-image-convert.sh

1	#!/bin/sh
2	
3	convert_webp_to_avif() {
4	    input_file="$1"
5	    output_file="${input_file%.webp}.avif"
6	    convert "$input_file" "$output_file"
7	}
8	
9	find . -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	
16	echo "Conversion complete!"

cn-char-lookup.sh

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

fuzzy-edit1.sh

1	#!/bin/sh
2	
3	clear &&
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	
3	clear &&
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	
3	echo "[" > s.json
4	
5	find . -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	
3	import png:- | xclip -selection c -t image/png