eat our own dog foot

This commit is contained in:
MorganGeek 2020-07-18 16:55:52 +02:00
parent 6fdba310b9
commit 641f25cc99
7 changed files with 54 additions and 46 deletions

View File

@ -21,3 +21,4 @@ alias words='file_getwords'
alias fd="\fd" alias fd="\fd"
alias wiki='wikit' alias wiki='wikit'
alias dico='dict' alias dico='dict'
alias topshellloc='| tr "|" "\n" | grep -v "function" | \grep -Eo "(.*)" | trim | sort | uniq -c | sort -nr'

View File

@ -25,7 +25,7 @@ fi
function _checkci() { function _checkci() {
local username local username
username="$(git config --global -l | grep "user.email" | cut -d'@' -f1 | cut -d'=' -f2)" username="$(git config --global -l G "user.email" | cut -d'@' -f1 | cut -d'=' -f2)"
local jenkinsfile="${1:-Jenkinsfile}" local jenkinsfile="${1:-Jenkinsfile}"
curl --user "$username:$JENKINS_SECRET" -X POST -F "jenkinsfile=<$jenkinsfile" "$JENKINS_URL/pipeline-model-converter/validate" curl --user "$username:$JENKINS_SECRET" -X POST -F "jenkinsfile=<$jenkinsfile" "$JENKINS_URL/pipeline-model-converter/validate"
} }

View File

@ -1,2 +1,3 @@
#!/usr/bin/env bash #!/usr/bin/env bash
npm list -g --depth 0 source $HOME/Code/dotfiles/dot_zsh_aliases
npmlist

View File

@ -17,7 +17,7 @@ function suggest_readable_parameters() {
if [[ $(LC_ALL=C type "$command_name") != *"alias for"* && $(LC_ALL=C type "$command_name") != *"is a shell function"* ]] && [[ $($command_name --help &>/dev/null) -eq 0 || $(info $command_name &>/dev/null) -eq 0 ]]; then if [[ $(LC_ALL=C type "$command_name") != *"alias for"* && $(LC_ALL=C type "$command_name") != *"is a shell function"* ]] && [[ $($command_name --help &>/dev/null) -eq 0 || $(info $command_name &>/dev/null) -eq 0 ]]; then
while read -r command_usage; do while read -r command_usage; do
arrow "searching for parameters in: $command_usage " arrow "searching for parameters in: $command_usage "
echo "$command_usage" | \grep -Eo "\b$command_name\b (\-[a-zA-Z0-9]*)" | head -1 | tr -d '-' | awk -v COUNT=1 'NF=COUNT' 1>/dev/null echo "$command_usage" | \grep -Eo "\b$command_name\b (\-[a-zA-Z0-9]*)" H -1 | tr -d '-' | awk -v COUNT=1 'NF=COUNT' 1>/dev/null
if [ $? -eq 0 ]; then if [ $? -eq 0 ]; then
while read -r command_parameters; do while read -r command_parameters; do
success "($command_name) -> found parameters : $command_parameters" success "($command_name) -> found parameters : $command_parameters"
@ -36,8 +36,8 @@ function suggest_readable_parameters() {
success "($command_name -$parameter_name) -> found better alternative to $parameter_name in $command_usage:" success "($command_name -$parameter_name) -> found better alternative to $parameter_name in $command_usage:"
info $command_name 2>/dev/null | \egrep -wo "(\-$parameter_name), --.*" info $command_name 2>/dev/null | \egrep -wo "(\-$parameter_name), --.*"
fi fi
done < <(echo "$command_parameters" | head -1 | tr -d '-' | fold -w 1) done < <(echo "$command_parameters" H -1 | tr -d '-' | fold -w 1)
done < <(echo "$command_usage" | \grep -Po "(?<=\b$command_name\b )(\-[a-zA-Z0-9]*)" | sort -u) #| head -1 | tr -d '-' | fold -w 1) done < <(echo "$command_usage" | \grep -Po "(?<=\b$command_name\b )(\-[a-zA-Z0-9]*)" | sort -u)
fi fi
done < <(grep -H -n "\b$command_name\b" "$@") done < <(grep -H -n "\b$command_name\b" "$@")
else else
@ -45,5 +45,5 @@ function suggest_readable_parameters() {
true true
fi fi
fi fi
done < <(top_commands "" 1000 | awk '{print $4}' | grep "^[\\\\]?[a-z]+$" | sort -u) done < <(top_commands "" 1000 | awk '{print $4}' G "^[\\\\]?[a-z]+$" | sort -u)
} }

View File

@ -22,7 +22,7 @@ bundle update --all
zsh ~/.oh-my-zsh/tools/upgrade.sh zsh ~/.oh-my-zsh/tools/upgrade.sh
sudo pip install --upgrade pip 2>/dev/null sudo pip install --upgrade pip 2>/dev/null
sudo pip3 install --upgrade pip 2>/dev/null sudo pip3 install --upgrade pip 2>/dev/null
pip list --outdated --format=freeze | grep -v '^\-e' | cut -d = -f 1 | xargs -n1 pip install -U pip list --outdated --format=freeze G -v '^\-e' | cut -d = -f 1 | xargs -n1 pip install -U
pip freeze >~/requirements.txt pip freeze >~/requirements.txt
# Update VIM plugins installed via Vundle https://github.com/VundleVim/Vundle.vim # Update VIM plugins installed via Vundle https://github.com/VundleVim/Vundle.vim
vim +PluginUpdate +qall >/dev/null vim +PluginUpdate +qall >/dev/null

View File

@ -1,6 +1,6 @@
#!/usr/bin/env bash #!/usr/bin/env bash
set -eo pipefail set -eo pipefail
vim --version | head -1 vim --version H -1
rustc --version rustc --version
npm --version npm --version
bats --version bats --version
@ -19,12 +19,12 @@ python3 --version
docker --version docker --version
openssl version openssl version
git --version git --version
atlas-version | grep Version | head -n 1 atlas-version G Version H -n 1
export SDKMAN_DIR="$HOME/.sdkman" export SDKMAN_DIR="$HOME/.sdkman"
[[ -s "$SDKMAN_DIR/bin/sdkman-init.sh" ]] && source "$SDKMAN_DIR/bin/sdkman-init.sh" [[ -s "$SDKMAN_DIR/bin/sdkman-init.sh" ]] && source "$SDKMAN_DIR/bin/sdkman-init.sh"
sdk --version sdk --version
tac --version | head -n 1 tac --version H -n 1
k9s version k9s version
tfsec --version tfsec --version
aws-iam-authenticator version aws-iam-authenticator version

View File

@ -122,12 +122,12 @@ function logtalk() {
function top_commands() { function top_commands() {
local filter="$1" local filter="$1"
local max_results=${2:-'50'} local max_results=${2:-'50'}
history | \cat | awk '{CMD[$2]++;count++;}END { for (a in CMD)print CMD[a] " " CMD[a]/count*100 "% " a; }' | grep -v "./" | column -c3 -s " " -t | grep "$filter" | sort -nr | nl | head "-n$max_results" history | \cat | awk '{CMD[$2]++;count++;}END { for (a in CMD)print CMD[a] " " CMD[a]/count*100 "% " a; }' G --invert-match "./" | column -c3 -s " " -t G "$filter" | sort --numeric-sort --reverse | nl H "-n$max_results"
} }
function top_commands_full() { function top_commands_full() {
local filter="$1" local filter="$1"
local max_results=${2:-'50'} local max_results=${2:-'50'}
history | \cat | awk '{$1=$1};1' | sed 's/^[0-9 TAB]*//g' | awk '{CMD[$0]++;count++;}END { for (a in CMD)print CMD[a] " " CMD[a]/count*100 "%\t" a; }' | grep "$filter" | sort -nr | nl | head "-n$max_results" history | \cat | awk '{$1=$1};1' | sed 's/^[0-9 TAB]*//g' | awk '{CMD[$0]++;count++;}END { for (a in CMD)print CMD[a] " " CMD[a]/count*100 "%\t" a; }' G "$filter" | sort --numeric-sort --reverse | nl H "-n$max_results"
} }
# Where is a function defined? # Where is a function defined?
function whichfunc() { function whichfunc() {
@ -145,10 +145,10 @@ function suggest_code_refactoring() {
local short_name=$(echo "$line" | sed -E "s/='.*//g") local short_name=$(echo "$line" | sed -E "s/='.*//g")
local alias_value=$(echo "$line" | sed -E 's/[a-zA-Z_-]+=//g') local alias_value=$(echo "$line" | sed -E 's/[a-zA-Z_-]+=//g')
local alias_value_truncated=${alias_value:1:$((${#alias_value} - 2))} local alias_value_truncated=${alias_value:1:$((${#alias_value} - 2))}
\fgrep $alias_value_truncated "$@" 2>/tmp/error.log | \grep -v "alias $short_name=" 1>/dev/null \fgrep -d skip $alias_value_truncated "$@" 2>/tmp/error.log | \grep --invert-match "alias $short_name=" 1>/dev/null
if [ $? -eq 0 ]; then if [ $? -eq 0 ]; then
success "found $short_name --> $alias_value_truncated" success "found $short_name --> $alias_value_truncated"
\fgrep "$alias_value_truncated" "$@" --color -n -H --line-buffered | \grep -v "alias $short_name=" \fgrep -d skip "$alias_value_truncated" "$@" --color -n -H --line-buffered | \grep --invert-match "alias $short_name="
else else
local error_message=$(\cat /tmp/error.log) local error_message=$(\cat /tmp/error.log)
if [ -n "$error_message" ]; then if [ -n "$error_message" ]; then
@ -171,17 +171,17 @@ function suggest_aliases() {
else else
warning "no alias for $line" warning "no alias for $line"
fi fi
done < <(top_commands_full "" "$search_input_size" | awk '{ $1=""; $2=""; $3=""; print}' | awk 'NF' | awk '{$1=$1};1' | awk -v COUNT=1 'NF>COUNT' | head "-$search_input_size") done < <(top_commands_full "" "$search_input_size" | awk '{ $1=""; $2=""; $3=""; print}' | awk 'NF' | awk '{$1=$1};1' | awk -v COUNT=1 'NF>COUNT' H "-$search_input_size")
} }
# Web Crawling # Web Crawling
function aboutpage() { function aboutpage() {
year=$(echo "$*" | egrep -Eo '\b[[:digit:]]{4}\b' | head -n1) year=$(echo "$*" | egrep --extended-regexp --only-matching '\b[[:digit:]]{4}\b' H -n1)
if [ -z "$year" ]; then if [ -z "$year" ]; then
year=$(curl -sSL "$*" | tr '<' '\r' | \egrep -i "date|datetime" -A 1 | \grep -Eo '\b[[:digit:]]{4}\b' | head -n1) year=$(curl --silent --show-error --location "$*" | tr '<' '\r' | \egrep --ignore-case "date|datetime" -A 1 | \grep --extended-regexp --only-matching '\b[[:digit:]]{4}\b' H -n1)
fi fi
author=$(curl -sSL "$*" | tr '<' '\r' | \egrep -i "author" -A 1 | \grep -Eo '([A-Z][A-Za-z]+\s([A-Za-z ]+)*)' | head -n1) author=$(curl --silent --show-error --location "$*" | tr '<' '\r' | \egrep --ignore-case "author" -A 1 | \grep --extended-regexp --only-matching '([A-Z][A-Za-z]+\s([A-Za-z ]+)*)' H -n1)
title=$(curl -sSL "$*" | tr '<' '<\n' | \grep title -A 1 | head -n1 | sed -E 's/.*<title>(.*)<\/title>.*/\1/' | sed "s/ [^[:alnum:]]*$author//") title=$(curl --silent -SL "$*" | tr '<' '<\n' | \grep title -A 1 H -n1 | sed -E 's/.*<title>(.*)<\/title>.*/\1/' | sed "s/ [^[:alnum:]]*$author//")
yearint=$(($year + 0)) yearint=$(($year + 0))
currentyear=$(echo $(date +"%Y")) currentyear=$(echo $(date +"%Y"))
if [ ! -z "$author" ]; then if [ ! -z "$author" ]; then
@ -231,11 +231,14 @@ cmd_loc="find . -type f \( \
# Unique lines of code # Unique lines of code
# Via https://text.causal.agency/004-uloc.txt # Via https://text.causal.agency/004-uloc.txt
function uloc() { function uloc() {
eval "$cmd_loc | LANG=C LC_CTYPE=C sort -u | wc -l" eval "$cmd_loc | LANG=C LC_CTYPE=C sort --unique | wc -l"
} }
# Top lines of code # Top lines of code
function toploc() { function toploc() {
eval "$cmd_loc | LANG=C LC_CTYPE=C cut -c 1-100 | LANG=C LC_CTYPE=C sort | uniq -c | LANG=C LC_CTYPE=C sort -nr | head -50" eval "$cmd_loc | LANG=C LC_CTYPE=C cut -c 1-100 | LANG=C LC_CTYPE=C sort | uniq -c | LANG=C LC_CTYPE=C sort --numeric-sort --reverse H -50"
}
function historyloc() {
top_commands_full "" 5000 topshellloc
} }
function how_in() { function how_in() {
where="$1" where="$1"
@ -244,11 +247,13 @@ function how_in() {
} }
# File name references in file # File name references in file
function filerefs() { function filerefs() {
\grep -Eo "\b([a-zA-Z.]+)\.([a-z]{2,4}\b)" "$1" \ FILENAME=${1:-README*)}
| sort -u \ \grep --extended-regexp --only-matching "\b([a-zA-Z.-]+)\.([a-z]{2,4}\b)" $FILENAME \
| egrep -vi "\.com|\.git|\.io|\net|\.org|\.se|\.me|\.fr|contributing\.md" | sort --unique \
| egrep --invert-match --ignore-case "\.com|\.git|\.io|\net|\.org|\.se|\.me|\.fr|contributing\.md"
} }
function invalid_file_refs() { function invalid_file_refs() {
FILENAME=${1:-"README.*"}
while read -r file_ref; do while read -r file_ref; do
arrow "processing $file_ref ..." arrow "processing $file_ref ..."
find . -name "$file_ref" 1>/dev/null find . -name "$file_ref" 1>/dev/null
@ -259,7 +264,7 @@ function invalid_file_refs() {
success "$file_ref was found in the project" success "$file_ref was found in the project"
fi fi
arrow "checking if $file_ref is present in the source code..." arrow "checking if $file_ref is present in the source code..."
source_refs=$(\grep "$file_ref" * -r -l | grep -v "$1" | wc -l 2>/dev/null | trim) source_refs=$(\grep "$file_ref" * -r -l G --invert-match "$FILENAME" | wc -l 2>/dev/null | trim)
if [ "$source_refs" -eq 0 ]; then if [ "$source_refs" -eq 0 ]; then
error "$file_ref was not found in source code" error "$file_ref was not found in source code"
else else
@ -268,7 +273,7 @@ function invalid_file_refs() {
success "$file_ref was found in $source_ref" success "$file_ref was found in $source_ref"
done < <(\grep "$file_ref" * -r -l) done < <(\grep "$file_ref" * -r -l)
fi fi
done < <(filerefs "$1") done < <(filerefs "$FILENAME")
} }
@ -279,7 +284,8 @@ function checkenlist() {
} }
function checkenremote() { function checkenremote() {
curl -Lks "$1" > /tmp/file && checkenlist /tmp/file curl --location --insecure --silent "$1" > /tmp/file && checkenlist /tmp/file
}
# Time management # Time management
function zoomtimeboxed() { function zoomtimeboxed() {
@ -293,11 +299,11 @@ function zoomtimeboxed() {
# File stats helpers # File stats helpers
# Find files bigger than X size and sort them by size # Find files bigger than X size and sort them by size
function biggerthan() { function biggerthan() {
find . -size "+$*" -type f -print0 | xargs -0 ls -Ssh | sort -z find . -size "+$*" -type f -print0 | xargs -0 ls -Ssh | sort --zero-terminated
} }
# To automatically ls when changing directory # To automatically ls when changing directory
function cd() { function cd() {
builtin cd "$@" && ls -latr builtin cd "$@" && ll -atr
} }
function mouse() { function mouse() {
case "$(uname -s)" in case "$(uname -s)" in
@ -369,7 +375,7 @@ function vimat() {
vim +/$1 $2 vim +/$1 $2
} }
function httperr() { function httperr() {
curl -s "https://http.cat/$1" | imgcat curl --silent "https://http.cat/$1" | imgcat
} }
# Config / Infra as code # Config / Infra as code
@ -412,7 +418,7 @@ function password() {
bw get password "$1" bw get password "$1"
} }
function vaultgetsecret() { function vaultgetsecret() {
local secret=$(grep -A 500 "ANSIBLE_VAULT" "$1" | awk '{$1=$1;print}' | \grep -Eo "^[0-9a-z^ ]+$") local secret=$(grep -A 500 "ANSIBLE_VAULT" "$1" | awk '{$1=$1;print}' | \grep --extended-regexp --only-matching "^[0-9a-z^ ]+$")
local secret_string=$(echo "\$ANSIBLE_VAULT;1.1;AES256\n$secret") local secret_string=$(echo "\$ANSIBLE_VAULT;1.1;AES256\n$secret")
echo "$secret_string" | awk '{$1=$1;print}' | ansible-vault decrypt --vault-password-file=$VAULT_PASSWORD_FILE echo "$secret_string" | awk '{$1=$1;print}' | ansible-vault decrypt --vault-password-file=$VAULT_PASSWORD_FILE
} }
@ -420,16 +426,17 @@ function vaultgetsecret() {
### Git helpers ### Git helpers
function backupgithub() { function backupgithub() {
cd "$REPO_PATH" cd "$REPO_PATH"
curl -sL "https://api.github.com/users/$1/repos" | jq -r '.[] | .ssh_url' | xargs -n1 git clone --mirror --no-hardlinks curl --silent --location "https://api.github.com/users/$1/repos" | jq -r '.[] | .ssh_url' | xargs -n1 git clone --mirror --no-hardlinks
} }
function gitydiff() { function gitydiff() {
local path_to_file="$1" local path_to_file="$1"
git show "HEAD:$path_to_file" | colordiff -y - "$path_to_file" gsh "HEAD:$path_to_file" | colordiff -y - "$path_to_file"
} }
function gcrb() { function gcrb() {
branch=$1 branch=$1
git checkout -b $branch origin/$branch gcb $branch origin/$branch
} }
function installhooks() { function installhooks() {
pre-commit install --install-hooks --overwrite --allow-missing-config pre-commit install --install-hooks --overwrite --allow-missing-config
} }
@ -465,13 +472,13 @@ function gitpushcurrentremote() {
function gitpushallremote() { function gitpushallremote() {
local param_branch="$1" local param_branch="$1"
grv grv
grv | grep push | awk '{print $1}' | while read -r remote; do grv G push | awk '{print $1}' | while read -r remote; do
if [ -z "$param_branch" ]; then if [ -z "$param_branch" ]; then
arrow "pushing all branches to $remote" arrow "pushing all branches to $remote"
git push --all "$remote" gp --all "$remote"
else else
arrow "pushing $param_branch to $remote" arrow "pushing $param_branch to $remote"
git push "$remote" "$param_branch" gp "$remote" "$param_branch"
fi fi
done done
} }
@ -516,7 +523,7 @@ function gitignorefor() {
arrow "cloning https://github.com/github/gitignore into $REPO_PATH/gitignore" arrow "cloning https://github.com/github/gitignore into $REPO_PATH/gitignore"
git clone "https://github.com/github/gitignore $_" git clone "https://github.com/github/gitignore $_"
fi fi
local gitignore_file=$(fd "$language" "$REPO_PATH/gitignore" | head -n1) local gitignore_file=$(fd "$language" "$REPO_PATH/gitignore" H -n1)
if [ ! -z "$gitignore_file" ]; then if [ ! -z "$gitignore_file" ]; then
success "matched gitignore file : $gitignore_file" success "matched gitignore file : $gitignore_file"
if [ ! -f "$(pwd)/.gitignore" ]; then if [ ! -f "$(pwd)/.gitignore" ]; then
@ -536,7 +543,7 @@ function colorpic() {
local result_url=$(\curl -F "image=@$picture_url" -H "api-key:$COLORPIC_APIKEY" https://api.deepai.org/api/colorizer -s | jq '.output_url' | strings) local result_url=$(\curl -F "image=@$picture_url" -H "api-key:$COLORPIC_APIKEY" https://api.deepai.org/api/colorizer -s | jq '.output_url' | strings)
success "Generated $result_url" success "Generated $result_url"
arrow "Display in progress..." arrow "Display in progress..."
eval "\curl -s $result_url | imgcat" eval "\curl --silent $result_url | imgcat"
} }
function bookmarkadd() { function bookmarkadd() {
@ -571,19 +578,18 @@ function goadd() {
go get -u -v "$1" go get -u -v "$1"
} }
# Make a directory and cd to it # Make a directory and cd to it
function take() { function take() {
mkdir -p "$@" && cd "${@:$#}" md -p "$@" && cd "${@:$#}"
} }
# Date / Time management helpers # Date / Time management helpers
function endofday() { function endofday() {
local planned_end=$(moro status 2>&1 | \grep -Eo "Working until ([0-9:]+) will make.*" | uniq | \grep -Eo "([0-9]+:[0-9]+)") local planned_end=$(moro status 2>&1 | \grep --extended-regexp --only-matching "Working until ([0-9:]+) will make.*" | uniq | \grep --extended-regexp --only-matching "([0-9]+:[0-9]+)")
local max_hour="$planned_end" local max_hour="$planned_end"
local min_hour=$(current_time) local min_hour=$(current_time)
if [ -z "$planned_end" ]; then if [ -z "$planned_end" ]; then
local clockout=$(moro report 2>&1 | \grep -Eo "Clock out.*([0-9:]+)" | \grep -Eo "([0-9]+:[0-9]+)") local clockout=$(moro report 2>&1 | \grep --extended-regexp --only-matching "Clock out.*([0-9:]+)" | \grep --extended-regexp --only-matching "([0-9]+:[0-9]+)")
max_hour="$clockout" max_hour="$clockout"
fi fi
if is_earlier "$min_hour" "$max_hour"; then if is_earlier "$min_hour" "$max_hour"; then
@ -611,11 +617,11 @@ function is_earlier() {
} }
function dl_stopwords() { function dl_stopwords() {
curl -Lks https://raw.githubusercontent.com/MorganGeek/bookmarks/master/stopwords.txt -o "$HOME/stopwords.txt" curl --location --insecure --silent https://raw.githubusercontent.com/MorganGeek/bookmarks/master/stopwords.txt -o "$HOME/stopwords.txt"
} }
function file_getwords() { function file_getwords() {
dl_stopwords dl_stopwords
\cat "$1" | tr '[:upper:]' '[:lower:]' | \grep -o -E '\w{3,}' | \grep --invert-match --word-regexp --fixed-strings --file="$HOME/stopwords.txt" | \sed 's/s$//g' | \sed 's/ing$//g' | sort_count \cat "$1" | tr '[:upper:]' '[:lower:]' | \grep --extended-regexp --only-matching '\w{3,}' | \grep --invert-match --word-regexp --fixed-strings --file="$HOME/stopwords.txt" | \sed 's/s$//g' | \sed 's/ing$//g' | sort_count
} }
function file_getpairs() { function file_getpairs() {
dl_stopwords dl_stopwords
@ -633,7 +639,7 @@ function chance() {
} }
function runiflucky() { function runiflucky() {
if chance "1-10"; then if chance "1-10"; then
if alias "$1" 2>/dev/null || (compgen -A function | grep "$1" 1>/dev/null && compgen -A function "$1" 1>/dev/null); then if alias "$1" 2>/dev/null || (compgen -A function G "$1" 1>/dev/null && compgen -A function "$1" 1>/dev/null); then
eval "$1" eval "$1"
fi fi
fi fi