# By Brian Tomasik (https://briantomasik.com/). # First published: 2019-11-10. Last update of any kind: 2021-02-01T04-06. # # To the extent possible under law, the author(s) have dedicated all copyright and related and neighboring rights to this software to the public domain worldwide. This software is distributed without any warranty. # Note: Below, when I say "run the bare command", this means typing the function name into Terminal without adding any parameters. alias lh='ls -lhAG' alias cp='cp -i' alias mv='mv -i' # 'lsod' stands for 'list only dirs'. The command is taken from the comment by Gergo in "[Listing only directories using ls in bash: An examination](https://stackoverflow.com/questions/14352290/listing-only-directories-using-ls-in-bash-an-examination)". alias lsod='ls -d .*/ */' # "bff" is "Bash functions file". This command shows the current file so that you can look up the names of all the other custom aliases and functions. # Usage: just run the bare command from anywhere mybff() { less ~/files/yebs/processed/scripts_ytmc/the-actual-bash-aliases-file.txt; } # Usage: just run the bare command from anywhere myd() { cd ~/files/yebs/unprocessed/downloads/; } # Usage: just run the bare command from anywhere mytodos() { cd ~/files/yebs/unprocessed/todos/; } # Usage: just run the bare command from anywhere # "myt" stands for "my todos for the current year". The name is short so that it's fast to type. myt() { mytodos && cd `date +'%Y'`; } # Usage: just run the bare command from anywhere myoft() { cd ~/files/yebs/processed/misc/check-me-often/; } # Usage: just run the bare command from anywhere mycal() { myoft && less calendar.txt; } # Usage: just run the bare command in the desired directory mydu() { du -h -d 2 | sort -h; } # Example usage: # mygrep amazon mygrep() { grep -rin --include \*.txt --exclude-dir=vxhx "$1" .; } # Example usage: # myhtmlgrep "insect suffering" # HTML files sometimes don't have enough newlines, causing the `grep` matching lines to be too long. This command only prints out up to 30 characters before and after the match. The second `grep` serves to color the text actually being searched for, rather than the entire output including the 30 characters before and after. This command is based on Stéphane Chazelas's answer on "[To grep 20 characters after and before match](https://unix.stackexchange.com/questions/121450/to-grep-20-characters-after-and-before-match)". myhtmlgrep() { grep -rinoE --include \*.html --include \*.htm --include \*.php --exclude-dir=vxhx ".{0,30}$1.{0,30}" . | grep --color "$1"; } # Example usage: # mysak stuff.tar.gz.gpg mysak() { python3 ~/files/yebs/processed/scripts_ytmc/Swiss-archive-knife.py "$1"; } # Usage: just run the bare command from anywhere mybackup() { cd ~/files/ && python3 ~/files/yebs/processed/scripts_ytmc/backup.py; } # Usage: just run the bare command from anywhere mytestbackup() { cd ~/test_files/ && python3 ~/files/yebs/processed/scripts_ytmc/backup.py -t; } # Example usage: # myvers foo.txt myvers() { python3 ~/files/yebs/processed/scripts_ytmc/create-a-version-snapshot.py "$1"; } # Usage: just run the bare command in the directory under which you want all file and folder names to be renamed if need be. # "nn" stands for "normalize names". mynn() { python3 ~/files/yebs/processed/scripts_ytmc/normalize-file-and-folder-names.py; } # Usage: just run the bare command from anywhere mymonitor() { cd ~/files/yebs/processed/scripts_ytmc/monitor-data-changes/ && python3 run.py; } # Show the highest-priority todo items. # Usage: just run the bare command from anywhere. # The `grep -v` omits this file itself from being included in the results. The final `grep` serves to re-highlight the grepped-for string after `sort` and `grep -v` have removed the original highlighting. At the end we go to the `mytodos` folder because after seeing these search results, that's the most likely place we'll want to be, since we can open a lot of todo files from there. my1t() { cd ~/files/ && mygrep "1t:" | sort | grep -v "/yebs/processed/scripts_ytmc/the-actual-bash-aliases-file" | grep "1t:" && mytodos; } # Show the highest-priority reminders. # Usage: just run the bare command from anywhere. my1r() { cd ~/files/ && mygrep "1r:" | sort | grep -v "/yebs/processed/scripts_ytmc/the-actual-bash-aliases-file" | grep "1r:" && mytodos; } # Example usage: # myshacheck sha512-of-file.txt # or # myshacheck sha512-of-everything.txt myshacheck() { shasum -c "$1" | grep -v ": OK"; } # Example usage: # myshaforonefile letter.pdf myshaforonefile() { if [ -f "sha512-of-file.txt" ]; then echo "'sha512-of-file.txt' already exists! Aborting." return fi shasum -a 512 "$1" >> sha512-of-file.txt } # Usage: Run the bare command in the directory that you want to checksum. The command is taken from [here](https://briantomasik.com/manual-file-fixity/#bulk). myshaofeverything() { if [ -f "sha512-of-everything.txt" ]; then echo "'sha512-of-everything.txt' already exists! Aborting." return fi find . ! -name ".DS_Store" ! -name "sha512-of-everything.txt" -type f -exec shasum -a 512 {} \; >> sha512-of-everything.txt } # Also load another Bash-aliases file that I use for myself but don't publish on my website. source ~/files/yebs/processed/scripts_ytmc/additional-Bash-aliases.txt