Last active
December 7, 2023 16:34
-
-
Save magmanu/64ee6572c1e2940d96b06948fa634194 to your computer and use it in GitHub Desktop.
Useful zsh aliases
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
mksecret() { | |
openssl rand -base64 14 | |
} | |
################## | |
# Terraform | |
################## | |
alias tfi="terraform init" | |
alias tfmt="terraform fmt --recursive" | |
alias tfpr="terraform plan && terraform fmt --recursive" | |
alias tfpexpt="terraform plan -out tf.plan && terraform show -no-color tf.plan > tfplan.txt" | |
tfsum() { | |
# Outputs a summary of resources to be create, deleted or updated on a tf plan. | |
# Credit to @tculp (https://github.com/hashicorp/terraform/issues/10507#issuecomment-1120333083) | |
terraform plan -json | \ | |
jq --slurp --raw-output ' | |
map( | |
select(.type == "planned_change") | | |
{ | |
addr: .change.resource.addr, | |
action: .change.action | |
} | |
) | | |
group_by(.action) | | |
map( | |
.[0].action as $action | | |
del (.[].action) | | |
map(.addr) | | |
"\($action) (\(. | length)):\n \(map(.) | join("\n "))\n" | |
) | | |
.[] | |
' | |
} | |
################## | |
# Vault | |
################## | |
alias awsdf="aws-vault exec my.aws.username" | |
alias awscl="unset AWS_VAULT" | |
################## | |
# GitHub | |
################## | |
# Create new branch from updated main | |
gbranch() { | |
git checkout main | |
git fetch --all | |
git pull | |
if [ -n "$1" ] | |
then | |
git checkout -b "$1" | |
else | |
echo "Main updated. Pass a value to create new branch" | |
fi | |
} | |
# Clone from your usual org to a specific folder | |
gclone() { | |
cd ~/Projects/ | |
if [ -n "$1" ] | |
then | |
git clone "https://github.com/org-or-user-name/$1.git" | |
cd "$1" | |
else | |
echo "Retry passing repo name" | |
fi | |
} | |
# Python: only perform git add if linting is clean | |
gadd() { | |
# pip install isort black pylint yamllint darglint pydocstyle | |
echo "Isort:" | |
python3 -m isort $(find . -name "*.py" -not -path "./tests/*") | |
echo "Black:" | |
python3 -m black $(find . -name "*.py" -not -path "./tests/*") | |
echo "Pylint:" | |
python3 -m pylint | |
echo "Yamllint:" | |
yamllint .yaml | |
yamllint .yml | |
echo "Darglint:" | |
darglint_results=$(find . -name "*.py" -not -path "./tests/*" -exec darglint {} \;) | |
echo "Pydocstyle:" | |
pydocstyle_results=$(find . -name "*.py" -not -path "./tests/*" -exec pydocstyle {} \;) | |
if [[ -z "$darglint_results" ]] && [[ -z "$pydocstyle_results" ]]; then | |
echo "All docstrings are valid" | |
git add . | |
else | |
echo "Invalid docstrings found:" | |
echo "$darglint_results" | |
echo "$pydocstyle_results" | |
exit 1 | |
fi | |
} | |
# Lists all my pending PRs with status and link | |
myprs(){ | |
gh api graphql -f query=' | |
{ | |
search(query: "is:open is:pr author:myusername", type: ISSUE, first: 100) { | |
issueCount | |
edges { | |
node { | |
... on PullRequest { | |
reviewDecision | |
url | |
} | |
} | |
} | |
} | |
}' | jq -r '[.data.search.edges | .[].node]' | |
} | |
################## | |
# AWS | |
################## | |
alias awsdecode='awsdecode() { | |
if [ -n "$1" ] | |
then | |
aws sts decode-authorization-message --encoded-message "$1" --query DecodedMessage --output text | jq '.' | |
else | |
echo "Guess you forgot the message?" | |
fi | |
};awsdecode' | |
################### | |
# Docker | |
################## | |
dcb() { | |
if [ -n "$1" ] | |
then | |
docker build -t "$1" | |
else | |
echo "Pass a name for the image" | |
fi | |
} | |
################## | |
# zsh customization | |
################## | |
# Add time on right-side prompt | |
RPROMPT='[%D{%H:%M:%S}]' | |
TMOUT=1 | |
TRAPALRM() { | |
zle reset-prompt | |
} | |
################## | |
#### Other | |
#### macOS crontab | |
################## | |
28 9 * * 1-5 current_vol=$(osascript -e 'output volume of (get volume settings)') && osascript -e "set volume output volume 65" && say "It's stand up time" && osascript -e "set volume output volume $current_vol" | |
30 12 * * * current_vol=$(osascript -e 'output volume of (get volume settings)') && osascript -e "set volume output volume 65" && say "Lunch break" && osascript -e "set volume output volume $current_vol" | |
57 9-17 * * * current_vol=$(osascript -e 'output volume of (get volume settings)') && osascript -e "set volume output volume 65" && say "Small break in 15 seconds" && osascript -e "set volume output volume $current_vol" && sleep 15 && osascript -e 'tell application "Finder" to sleep' | |
0 18 * * 1-5 current_vol=$(osascript -e 'output volume of (get volume settings)') && osascript -e "set volume output volume 65" && say "Finishing in 45 seconds" && osascript -e "set volume output volume $current_vol" && sleep 45 && osascript -e 'tell application "Finder" to sleep' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment