References
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Example to show how to append piped/redirected input to arg array | |
# | |
# More info: | |
# `man test` (lookup -t flag) | |
# `man zshbuiltins` (lookup set builtin) | |
# | |
# piped_input_example | |
# piped_input_example --flag arg | |
# piped_input_example --opt1 -x -y -z param1 param2 <<< "zzz" | |
# echo "abc" | piped_input_example --opt1 -x -y -z param1 param2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env zsh | |
##? plugin-load - load plugins without a fancy plugin manager | |
##? | |
##? usage: plugin-load [-h|--help] | |
##? plugin-load [-n|--no-source] [-d|--defer] [-f|--fpath] [-p|--path] | |
##? [-u|--use-dir <plugin-subdir>] [<repo...>] | |
function plugin-load { | |
local use_dir flag_no_source flag_fpath flag_path flag_defer repos=() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function freq { | |
for c in $@; do | |
for c2 in $@; do | |
grep "$c$c2" /usr/share/dict/words | wc -l | tr -d '\n' && echo " $c$c2" | |
done | |
done | |
} | |
# least frequent home row bigrams | |
freq a r s t d h n e i o | sort -d | uniq | head -n 10 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 'ls' after every 'cd' | |
if ! (( $chpwd_functions[(I)chpwd_cdls] )); then | |
chpwd_functions+=(chpwd_cdls) | |
fi | |
function chpwd_cdls() { | |
if [[ -o interactive ]]; then | |
emulate -L zsh | |
ls | |
fi | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env zsh | |
GNUPGHOME=${XDG_DATA_HOME:-$HOME/.local/share}/gnupg | |
mkdir -p $GNUPGHOME | |
chown -R $(whoami) $GNUPGHOME | |
chmod 600 $GNUPGHOME/* | |
chmod 700 $GNUPGHOME |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
""" | |
This is a Python implementation of the algorithm to generate | |
Google Authenticator multi-factor authentication tokens from | |
an MFA secret key. | |
usage: | |
secret=KUSJRAVCONHIBBKW |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Manual opt parsing example | |
# | |
# Features: | |
# - supports short and long flags (ie: -v|--verbose) | |
# - supports short and long key/value options (ie: -f <file> | --filename <file>) | |
# - supports short and long key/value options with equals assignment (ie: -f=<file> | --filename=<file>) | |
# - does NOT support short option chaining (ie: -vh) | |
# - everything after -- is positional even if it looks like an option (ie: -f) | |
# - once we hit an arg that isn't an option flag, everything after that is considered positional | |
function optparsing_demo() { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function day10 \ | |
--description "https://adventofcode.com/2021/day/10 - usage: day10 datafile.dat" \ | |
--argument-names datafile | |
test -f "$datafile"; or echo >&2 "file expected" && return 1 | |
# find corrupted lines | |
set --local data (cat $datafile) | |
set --local line_num 0 | |
set --local total_error_score 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function day9 \ | |
--description "https://adventofcode.com/2021/day/9 - usage: day9 part1 datafile.dat" \ | |
--argument-names part datafile | |
test -f "$datafile"; or echo >&2 "file expected" && return 1 | |
set part (string match --regex '.$' $part) | |
day9part$part $datafile | |
end |