fix technical debt + fine tune functions and hooks

- linting/fixing/formating
- utility for suggesting aliases now accepts parameters to change output
  size
- add helper to checkci
- add verify committer script to avoid committer with wrong git identify
This commit is contained in:
MorganGeek 2020-07-12 16:19:25 +02:00
parent 336aaa2729
commit 3a3fc30b8c
16 changed files with 308 additions and 230 deletions

View File

@ -1,3 +1,4 @@
---
policies: policies:
- type: commit - type: commit
spec: spec:
@ -15,7 +16,7 @@ policies:
maximumOfOneCommit: true maximumOfOneCommit: true
conventional: conventional:
types: types:
- "type" - type
scopes: scopes:
- "scope" - scope
descriptionLength: 72 descriptionLength: 72

View File

@ -1,3 +1,4 @@
---
#- search: /Something [bB]ad/ #- search: /Something [bB]ad/
# replacement: Something Good # replacement: Something Good
#- search: foobar #- search: foobar

View File

@ -1,4 +1,5 @@
---
- name: No FIXME - name: No FIXME
pattern: 'FIXME' pattern: FIXME
- name: No TODO - name: No TODO
pattern: 'TODO' pattern: TODO

View File

@ -1,3 +1,7 @@
# Introduction
[![pre-commit](https://img.shields.io/badge/pre--commit-enabled-brightgreen?logo=pre-commit&logoColor=white)](https://github.com/pre-commit/pre-commit)
## Prerequisites ## Prerequisites
### Centos ### Centos
@ -34,13 +38,13 @@ run `zsh .scripts/upgrade.sh`
- Install pip and pipenv - Install pip and pipenv
- Install AWS-CLI - Install AWS-CLI
### If Yubico is installed, run this : ### If Yubico is installed, run this
`sudo ansible-playbook ~/.scripts/ansible/macsecure_playbook.yaml` `sudo ansible-playbook ~/.scripts/ansible/macsecure_playbook.yaml`
#### In cases of `\n` errors with zsh #### In cases of `\n` errors with zsh
https://github.com/robbyrussell/oh-my-zsh/issues/6764#issuecomment-384045008 [Source](https://github.com/robbyrussell/oh-my-zsh/issues/6764#issuecomment-384045008)
``` ```
cd $ZSH cd $ZSH

View File

@ -53,7 +53,7 @@ chmod 755 /bin/git-ftp
yum install golang golang-godoc golang-vet golang-src golang-pkg-linux-amd64 -y yum install golang golang-godoc golang-vet golang-src golang-pkg-linux-amd64 -y
echo "export GOPATH=\"$HOME/go\"" >>~/.zshrc echo "export GOPATH=\"$HOME/go\"" >>~/.zshrc
echo "export PATH=\"$GOPATH/bin:$PATH\"" >>~/.zshrc echo "export PATH=\"$GOPATH/bin:$PATH\"" >>~/.zshrc
. ~/.zshrc . "$HOME/.zshrc"
# Install Hugo # Install Hugo
mkdir "$HOME/src" mkdir "$HOME/src"

View File

@ -16,12 +16,15 @@ repos:
- id: detect-aws-credentials - id: detect-aws-credentials
- id: detect-private-key - id: detect-private-key
- id: end-of-file-fixer - id: end-of-file-fixer
- id: flake8
- id: mixed-line-ending - id: mixed-line-ending
- id: pretty-format-json - id: pretty-format-json
- id: requirements-txt-fixer - id: requirements-txt-fixer
- id: sort-simple-yaml - id: sort-simple-yaml
- id: trailing-whitespace - id: trailing-whitespace
- repo: https://gitlab.com/pycqa/flake8.git
rev: master
hooks:
- id: flake8
- repo: git://github.com/antonbabenko/pre-commit-terraform - repo: git://github.com/antonbabenko/pre-commit-terraform
rev: v1.31.0 # Get the latest from: https://github.com/antonbabenko/pre-commit-terraform/releases rev: v1.31.0 # Get the latest from: https://github.com/antonbabenko/pre-commit-terraform/releases
hooks: hooks:
@ -63,13 +66,6 @@ repos:
pass_filenames: false pass_filenames: false
args: [-l=infra] #NOTE: that this is the directory you created earlier to host your terraform args: [-l=infra] #NOTE: that this is the directory you created earlier to host your terraform
verbose: true verbose: true
- repo: https://github.com/askulkarni2/pre-commit-docker-jenkinslint
rev: 88dd7702e44bbc4dc742b37897e1ded7fe99dfba
hooks:
- id: docker-jenkinslint
language: docker_image
entry: --entrypoint /usr/local/bin/run-jflint.sh askulkarni2/jenkinslint
files: Jenkinsfile
- repo: https://github.com/Lucas-C/pre-commit-hooks-nodejs - repo: https://github.com/Lucas-C/pre-commit-hooks-nodejs
rev: v1.1.1 rev: v1.1.1
hooks: hooks:
@ -92,7 +88,6 @@ repos:
rev: 1.2.0 rev: 1.2.0
hooks: hooks:
- id: relint - id: relint
- repo: git@github.com:Vimjas/vint.git - repo: git@github.com:Vimjas/vint.git
rev: master rev: master
hooks: hooks:
@ -104,3 +99,18 @@ repos:
- id: conform - id: conform
stages: stages:
- commit-msg - commit-msg
- repo: local
hooks:
- id: check-committer
name: Check Committer Identity
entry: pre-commit-verify-committer
language: system
always_run: true
files: ''
- repo: https://github.com/askulkarni2/pre-commit-docker-jenkinslint
rev: 88dd7702e44bbc4dc742b37897e1ded7fe99dfba
hooks:
- id: docker-jenkinslint
language: docker_image
entry: --entrypoint /usr/local/bin/run-jflint.sh askulkarni2/jenkinslint
files: Jenkinsfile

View File

@ -4,48 +4,48 @@ echo "Hello $(whoami)! Let's get you set up."
# Make sure Code directory exists # Make sure Code directory exists
echo "mkdir -p $HOME/Code" echo "mkdir -p $HOME/Code"
mkdir -p ~/Code mkdir -p "$HOME/Code"
ln -snf ~/Code/dotfiles/dot_scripts ~/.scripts ln -snf "$HOME/Code/dotfiles/dot_scripts" "$HOME/.scripts"
chmod +x ~/.scripts/*.sh chmod +x "$HOME/.scripts/*.sh"
~/.scripts/install_linux_packages.sh "$HOME/.scripts/install_linux_packages.sh"
~/.scripts/install_homebrew.sh "$HOME/.scripts/install_homebrew.sh"
# Path to ruby # Path to ruby
export PATH="/usr/local/opt/ruby/bin:$PATH" export PATH="/usr/local/opt/ruby/bin:$PATH"
# Create symbolic links # Create symbolic links
~/.scripts/symbolic_links.sh "$HOME/.scripts/symbolic_links.sh"
# Install user applications # Install user applications
~/.scripts/install_macpackages.sh "$HOME/.scripts/install_macpackages.sh"
~/.scripts/install_linux_user_apps.sh "$HOME/.scripts/install_linux_user_apps.sh"
# Switch to ZSH # Switch to ZSH
echo "switching to ZSH" echo "switching to ZSH"
command -v zsh >>/etc/shells command -v zsh >>/etc/shells
chsh -s "$(command -v zsh)" chsh -s "$(command -v zsh)"
~/.scripts/sdkmandeps.sh "$HOME/.scripts/sdkmandeps.sh"
~/.scripts/rubydeps.sh "$HOME/.scripts/rubydeps.sh"
~/.scripts/bundlerdeps.sh "$HOME/.scripts/bundlerdeps.sh"
~/.scripts/ohmyzshdeps.sh "$HOME/.scripts/ohmyzshdeps.sh"
~/.scripts/vimdeps.sh "$HOME/.scripts/vimdeps.sh"
~/.scripts/install_no-more-secrets.sh "$HOME/.scripts/install_no-more-secrets.sh"
~/.scripts/load_macos_defaults.sh "$HOME/.scripts/load_macos_defaults.sh"
~/.scripts/configure_etc_hosts.sh "$HOME/.scripts/configure_etc_hosts.sh"
~/.scripts/pythondeps.sh "$HOME/.scripts/pythondeps.sh"
~/.scripts/install_baton.sh "$HOME/.scripts/install_baton.sh"
~/.scripts/rustdeps.sh "$HOME/.scripts/rustdeps.sh"
~/.scripts/npmdeps.sh "$HOME/.scripts/npmdeps.sh"
terraform-docs completion zsh >/usr/local/share/zsh/site-functions/_terraform-docs terraform-docs completion zsh >/usr/local/share/zsh/site-functions/_terraform-docs
autoload -U compinit && compinit autoload -U compinit && compinit
~/.scripts/godeps.sh "$HOME/.scripts/godeps.sh"
~/.scripts/install_weavescope.sh "$HOME/.scripts/install_weavescope.sh"
~/.scripts/install_bashtop.sh "$HOME/.scripts/install_bashtop.sh"
~/.scripts/install_awsls.sh "$HOME/.scripts/install_awsls.sh"
~/.scripts/configure_git_hooks.sh "$HOME/.scripts/configure_git_hooks.sh"
~/.scripts/upgrade.sh "$HOME/.scripts/upgrade.sh"
~/.scripts/reload.sh "$HOME/.scripts/reload.sh"

View File

@ -1,4 +1,28 @@
#!/usr/bin/env bash #!/usr/bin/env bash
###
### checkci — checks a Jenkinsfile syntax against a real Jenkins instance
###
### Note: this script gets:
### the (jenkins) username from git config
### the (jenkins) password/secret from Environment variable $JENKINS_SECRET
### the (jenkins) URL from Environment variable $JENKINS_URL
###
### Usage:
### checkci.sh [jenkinsfile]
###
### Options:
### [input] path to Jenkinsfile (optional).
### -h Show this message.
help() {
gsed -rn 's/^### ?//;T;p' "$0"
}
if [[ $# == 0 ]] || [[ "$1" == "-h" ]]; then
help
exit 1
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 | grep "user.email" | cut -d'@' -f1 | cut -d'=' -f2)"

View File

@ -1,6 +1,6 @@
#!/usr/bin/env bash #!/usr/bin/env bash
# Copy pre-commit hooks # Copy pre-commit hooks
cd ~/Code/dotfiles || exit cd "$HOME/Code/dotfiles" || exit
git config --global init.templateDir ~/.git-template git config --global init.templateDir ~/.git-template
pre-commit init-templatedir ~/.git-template pre-commit init-templatedir ~/.git-template
copyhooks copyhooks

View File

@ -0,0 +1,31 @@
#!/bin/bash
#
# An example hook script to verify what is about to be committed.
# Called by "git commit" with no arguments. The hook should
# exit with non-zero status after issuing an appropriate message if
# it wants to stop the commit.
# shellcheck disable=SC1090
source "$HOME/.zsh_functions"
source "$HOME/.scripts/secrets.sh"
REMOTE=$(git config --get remote.origin.url)
USERNAME=$(git config --get user.name)
EMAIL=$(git config --get user.email)
checkEmailUsername() {
if [[ "$EMAIL" != "$1" ]]; then
warning "Invalid email: $EMAIL for remote $REMOTE"
arrow "fix this by running :\ngit config user.email $1"
exit 1
fi
if [[ "$USERNAME" != "$2" ]]; then
warning "Invalid username: $USERNAME for remote $REMOTE"
arrow "fix this by running :\ngit config user.name \"$2\""
exit 1
fi
}
if [[ $REMOTE == *"$COMPANY_NAME"* ]] && [[ "$REMOTE" != *"dotfiles"* ]]; then
checkEmailUsername "$GIT_PRO_EMAIL" "$GIT_PRO_USER"
else
checkEmailUsername "$GIT_PERSONAL_EMAIL" "$GIT_PERSONAL_USER"
fi

View File

@ -2,6 +2,7 @@
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"
# shellcheck disable
# Reload # Reload
echo "Reloading config" echo "Reloading config"

View File

@ -1,39 +1,40 @@
#!/usr/bin/env bash #!/usr/bin/env bash
echo "Creating symbolic links" echo "Creating symbolic links"
ln -snf ~/Code/dotfiles/dot_profile ~/.profile ln -snf "$HOME/dotfiles/dot_profile" "$HOME/.profile"
ln -snf ~/.local/share/chezmoi/ ~/dotfiles ln -snf "$HOME/.local/share/chezmoi/" "$HOME/dotfiles"
ln -snf ~/Code/dotfiles/Gemfile ~/Gemfile ln -snf "$HOME/dotfiles/Gemfile" "$HOME/Gemfile"
ln -snf ~/Code/dotfiles/README.md ~/README.md ln -snf "$HOME/dotfiles/README.md" "$HOME/README.md"
ln -snf ~/Code/dotfiles/dot_bash_profile ~/.bash_profile ln -snf "$HOME/dotfiles/dot_bash_profile" "$HOME/.bash_profile"
ln -snf ~/Code/dotfiles/dot_gitconfig ~/.gitconfig ln -snf "$HOME/dotfiles/dot_gitconfig" "$HOME/.gitconfig"
ln -snf ~/Code/dotfiles/dot_macos ~/.macos ln -snf "$HOME/dotfiles/dot_macos" "$HOME/.macos"
ln -snf ~/Code/dotfiles/dot_scripts ~/.scripts ln -snf "$HOME/dotfiles/dot_scripts" "$HOME/.scripts"
ln -snf ~/Code/dotfiles/dot_scripts/checkci.sh /usr/local/bin/checkci ln -snf "$HOME/dotfiles/dot_scripts/checkci.sh" /usr/local/bin/checkci
ln -snf ~/Code/dotfiles/dot_vimrc ~/.vimrc ln -snf "$HOME/dotfiles/dot_scripts/pre-commit-verify-committer.sh" /usr/local/bin/pre-commit-verify-committer
ln -snf "$HOME/dotfiles/dot_vimrc" "$HOME/.vimrc"
# custom linters # custom linters
ln -snf ~/Code/dotfiles/dot_vim/ale_linters ~/.vim/ale_linters ln -snf "$HOME/dotfiles/dot_vim/ale_linters" "$HOME/.vim/ale_linters"
ln -snf ~/Code/dotfiles/dot_aliases ~/.aliases ln -snf "$HOME/dotfiles/dot_aliases" "$HOME/.aliases"
ln -snf ~/Code/dotfiles/dot_zsh_aliases ~/.zsh_aliases ln -snf "$HOME/dotfiles/dot_zsh_aliases" "$HOME/.zsh_aliases"
ln -snf ~/Code/dotfiles/dot_zsh_functions ~/.zsh_functions ln -snf "$HOME/dotfiles/dot_zsh_functions" "$HOME/.zsh_functions"
ln -snf ~/Code/dotfiles/dot_zshrc ~/.zshrc ln -snf "$HOME/dotfiles/dot_zshrc" "$HOME/.zshrc"
ln -snf ~/Code/dotfiles/dot_zshrc.pre-oh-my-zsh ~/.zshrc.pre-oh-my-zsh ln -snf "$HOME/dotfiles/dot_zshrc.pre-oh-my-zsh" "$HOME/.zshrc.pre-oh-my-zsh"
ln -snf ~/Code/dotfiles/private_dot_ssh/config ~/.ssh/config ln -snf "$HOME/dotfiles/private_dot_ssh/config" "$HOME/.ssh/config"
ln -snf ~/Code/dotfiles/requirements.txt ~/requirements.txt ln -snf "$HOME/dotfiles/requirements.txt" "$HOME/requirements.txt"
ln -snf ~/Code/dotfiles/dot_surfraw.conf ~/.surfraw.conf ln -snf "$HOME/dotfiles/dot_surfraw.conf" "$HOME/.surfraw.conf"
ln -snf ~/Code/dotfiles/private_dot_3llo/config.sh ~/.3llo_config ln -snf "$HOME/dotfiles/private_dot_3llo/config.sh" "$HOME/.3llo_config"
ln -snf ~/Code/dotfiles/dot_ansiweatherrc ~/.ansiweatherrc ln -snf "$HOME/dotfiles/dot_ansiweatherrc" "$HOME/.ansiweatherrc"
ln -snf ~/Code/dotfiles/dot_p10k.zsh ~/.p10k.zsh ln -snf "$HOME/dotfiles/dot_p10k.zsh" "$HOME/.p10k.zsh"
ln -snf ~/Code/dotfiles/dot_git-template ~/.git-template ln -snf "$HOME/dotfiles/dot_git-template" "$HOME/.git-template"
ln -snf ~/Code/dotfiles/private_dot_newsboat ~/.newsboat ln -snf "$HOME/dotfiles/private_dot_newsboat" "$HOME/.newsboat"
ln -snf ~/Code/dotfiles/private_dot_config/Code ~/.config/Code ln -snf "$HOME/dotfiles/private_dot_config/Code" "$HOME/.config/Code"
ln -snf ~/Code/dotfiles/private_dot_config/neofetch ~/.config/neofetch ln -snf "$HOME/dotfiles/private_dot_config/neofetch" "$HOME/.config/neofetch"
ln -snf ~/Code/dotfiles/private_dot_config/gh ~/.config/gh ln -snf "$HOME/dotfiles/private_dot_config/gh" "$HOME/.config/gh"
ln -snf ~/Code/dotfiles/private_dot_config/htop ~/.config/htop ln -snf "$HOME/dotfiles/private_dot_config/htop" "$HOME/.config/htop"
ln -snf ~/Code/dotfiles/private_dot_config/bashtop ~/.config/bashtop ln -snf "$HOME/dotfiles/private_dot_config/bashtop" "$HOME/.config/bashtop"
ln -snf ~/Code/dotfiles/private_dot_config/wtf ~/.config/wtf ln -snf "$HOME/dotfiles/private_dot_config/wtf" "$HOME/.config/wtf"
ln -snf ~/Code/dotfiles/private_dot_config/yamllint ~/.config/yamllint ln -snf "$HOME/dotfiles/private_dot_config/yamllint" "$HOME/.config/yamllint"
ln -snf ~/Code/dotfiles/dot_git-template/.pre-commit-config.yaml ~/Code/dotfiles/.pre-commit-config.yaml ln -snf "$HOME/dotfiles/dot_git-template/.pre-commit-config.yaml" "$HOME/dotfiles/.pre-commit-config.yaml"
# Other symbolic links + Install Docker Desktop for Mac # Other symbolic links + Install Docker Desktop for Mac
case "$(uname -s)" in case "$(uname -s)" in

View File

@ -100,13 +100,18 @@ let g:ale_fix_on_save = 1
let g:ale_completion_enabled = 1 let g:ale_completion_enabled = 1
let g:ale_open_list = 1 let g:ale_open_list = 1
"\ 'yaml': ['prettier'], "\ 'yaml': ['prettier'],
let g:ale_fixers = { let g:ale_fixers = {
\ '*': ['remove_trailing_lines', 'trim_whitespace'], \ '*': ['remove_trailing_lines', 'trim_whitespace'],
\ 'python': ['black'], \ 'python': ['black'],
\ 'rust': ['rustfmt'], \ 'rust': ['rustfmt'],
\ 'Jenkinsfile': ['checkci'], \ 'Jenkinsfile': ['checkci'],
\ 'sh' : ['shfmt'],
\ 'zsh' : ['shfmt'],
\} \}
let g:ale_linters = {'zsh': ['shellcheck']}
" when running at every change you may want to disable quickfix " when running at every change you may want to disable quickfix
let g:prettier#quickfix_enabled = 1 let g:prettier#quickfix_enabled = 1
let g:prettier#quickfix_auto_focus = 1 let g:prettier#quickfix_auto_focus = 1
@ -188,6 +193,7 @@ let g:syntastic_python_checkers = ['pylint']
let g:syntastic_shell_checkers = ['shellcheck'] let g:syntastic_shell_checkers = ['shellcheck']
let g:syntastic_yaml_checkers = ['yamllint'] let g:syntastic_yaml_checkers = ['yamllint']
let g:syntastic_vim_checkers = ['vint'] let g:syntastic_vim_checkers = ['vint']
let g:syntastic_zsh_checkers = ['shellcheck']
set statusline+=%#warningmsg# set statusline+=%#warningmsg#
set statusline+=%{SyntasticStatuslineFlag()} set statusline+=%{SyntasticStatuslineFlag()}
@ -198,3 +204,4 @@ let g:syntastic_auto_loc_list = 1
let g:syntastic_check_on_open = 1 let g:syntastic_check_on_open = 1
let g:syntastic_check_on_wq = 0 let g:syntastic_check_on_wq = 0
au BufNewFile,BufRead Jenkinsfile setf groovy au BufNewFile,BufRead Jenkinsfile setf groovy
au BufRead,BufNewFile *.sh setfiletype sh

View File

@ -14,7 +14,7 @@ alias origin='setorigin'
alias goto='git go' alias goto='git go'
alias master='goto master' alias master='goto master'
alias develop='goto develop' alias develop='goto develop'
alias gg='git config -l | grep -i' # search git config for ... alias gg='git config -l | grip' # search git config for ...
alias ucommit='PRE_COMMIT_ALLOW_NO_CONFIG=1 git commit --no-verify' alias ucommit='PRE_COMMIT_ALLOW_NO_CONFIG=1 git commit --no-verify'
# Docker # Docker
@ -68,14 +68,14 @@ alias feeds='rss'
alias ddg='ddgr' alias ddg='ddgr'
alias goo='googler' alias goo='googler'
alias se='sr -elvi' alias se='sr -elvi'
alias eg='env | grep -i' # search env variables for pattern alias eg='env | grip' # search env variables for pattern
alias engines='sr -elvi' alias engines='sr -elvi'
alias grep='rg' alias grep='rg'
alias grip='grep -i' alias grip='grep -i'
alias usernames="python3 $HOME/Code/sherlock/sherlock.py --rank --print-found" alias usernames="python3 $HOME/Code/sherlock/sherlock.py --rank --print-found"
alias ygg="torrengo -s ygg" alias ygg="torrengo -s ygg"
alias ag='alias | grep -i' # search for patten among aliases alias ag='alias | grip' # search for patten among aliases
alias hg='history | grep -i' # search for pattern among history alias hg='history | grip' # search for pattern among history
alias hist='history' alias hist='history'
alias codestats='tokei' alias codestats='tokei'
alias dups='file_dups' alias dups='file_dups'
@ -134,7 +134,7 @@ alias ctrl-c='pbcopy'
alias s=ls alias s=ls
alias sl=ll alias sl=ll
alias ls='lsd' alias ls='lsd'
alias lsg='ll | grep -i' # show me files matching "ls grep" alias lsg='ll | grip' # show me files matching "ls grep"
alias lh='ls -alt | head' # see the last modified files alias lh='ls -alt | head' # see the last modified files
alias tree='ls --almost-all --tree' alias tree='ls --almost-all --tree'
alias v=vi alias v=vi
@ -180,12 +180,13 @@ alias current_year='`echo date +"%Y"`'
alias headers='curl -I --compress' # Find out if remote server supports gzip / mod_deflate or not # alias headers='curl -I --compress' # Find out if remote server supports gzip / mod_deflate or not #
alias https='http --default-scheme=https' # useful alias stealed from a colleague. http is provided by httpie alias https='http --default-scheme=https' # useful alias stealed from a colleague. http is provided by httpie
alias path='echo -e ${PATH//:/\\n}' # Explode and display current PATH alias path='echo -e ${PATH//:/\\n}' # Explode and display current PATH
alias p='ps -ef | grep -i ' # Show matching processes. Usage : p <process name> alias p='ps -ef | grip ' # Show matching processes. Usage : p <process name>
alias root='sudo -i' alias root='sudo -i'
alias ':q'='exit' alias ':q'='exit'
alias current_hour='date +"%H:%M"' alias current_hour='date +"%H:%M"'
alias current_time='current_hour' alias current_time='current_hour'
alias runhooks='pre-commit run -a' alias runhooks='pre-commit run -a'
alias tryhook='pre-commit try-repo .'
alias whatyear='current_year' alias whatyear='current_year'
alias whathour='current_time' alias whathour='current_time'
alias whattime='whathour' alias whattime='whathour'
@ -193,6 +194,7 @@ alias whattime='whathour'
# Linters # Linters
alias checken="aspell check -d en" alias checken="aspell check -d en"
alias checkfr="aspell check -d fr" alias checkfr="aspell check -d fr"
alias fixallscripts="shfmt -w -l -i 2 -ci **/*.sh"
# Development # Development
alias gw='./gradlew' alias gw='./gradlew'

View File

@ -98,39 +98,39 @@ function git_listobjectsbysize() {
done done
# sort files by SHA1, de-dupe list and finally re-sort by filesize # sort files by SHA1, de-dupe list and finally re-sort by filesize
sort --key 3 "$tempFile" | \ sort --key 3 "$tempFile" |
uniq | \ uniq |
sort --key 4 --numeric-sort --reverse sort --key 4 --numeric-sort --reverse
# remove temp file # remove temp file
rm -f "$tempFile" rm -f "$tempFile"
} }
function top_commands() { function top_commands() {
local filter="$1" local filter="$1"
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 -n50 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"
} }
function top_commands_full() { function top_commands_full() {
local filter="$1" local filter="$1"
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 -n50 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"
} }
function suggest_aliases() { function suggest_aliases() {
local search_input_size=${1:-'50'}
header "alias recommendations" header "alias recommendations"
while read -r line while read -r line; do
do
local matching_aliases=$(ag "$line") local matching_aliases=$(ag "$line")
if [ ! -z "$matching_aliases" ]; then if [ ! -z "$matching_aliases" ]; then
success "there is an alias for $line :" success "there is an alias for $line :"
while read -r alias_line while read -r alias_line; do
do
arrow "$alias_line" arrow "$alias_line"
done < <(echo "$matching_aliases") done < <(echo "$matching_aliases")
echo echo
fi fi
done < <(top_commands_full | awk '{ $1=""; $2=""; $3=""; print}' | awk 'NF' | awk '{$1=$1};1' | awk -v COUNT=1 'NF>COUNT' | head -20) 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")
} }
function istherenewissues() { function istherenewissues() {
LASTISSUE=$(newissues | sed $'s,\x1b\\[[0-9;]*[a-zA-Z],,g' | awk 'FNR==2{print $2}') LASTISSUE=$(newissues | sed $'s,\x1b\\[[0-9;]*[a-zA-Z],,g' | awk 'FNR==2{print $2}')
if [[ -f "$HOME/.newjiraissue" ]] if [[ -f "$HOME/.newjiraissue" ]]; then
then
previous_jira_issue=$(\cat "$HOME/.newjiraissue" | sed $'s,\x1b\\[[0-9;]*[a-zA-Z],,g') # the sed part is for removing output colors previous_jira_issue=$(\cat "$HOME/.newjiraissue" | sed $'s,\x1b\\[[0-9;]*[a-zA-Z],,g') # the sed part is for removing output colors
if [ "$LASTISSUE" != "$previous_jira_issue" ]; then if [ "$LASTISSUE" != "$previous_jira_issue" ]; then
newissues newissues
@ -142,24 +142,20 @@ function istherenewissues() {
} }
function aboutpage() { function aboutpage() {
year=$(echo "$*" | egrep -Eo '\b[[:digit:]]{4}\b' | head -n1) year=$(echo "$*" | egrep -Eo '\b[[:digit:]]{4}\b' | head -n1)
if [ -z "$year" ] if [ -z "$year" ]; then
then
year=$(curl -sSL "$*" | tr '<' '\r' | \egrep -i "date|datetime" -A 1 | \grep -Eo '\b[[:digit:]]{4}\b' | head -n1) year=$(curl -sSL "$*" | tr '<' '\r' | \egrep -i "date|datetime" -A 1 | \grep -Eo '\b[[:digit:]]{4}\b' | head -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 -sSL "$*" | tr '<' '\r' | \egrep -i "author" -A 1 | \grep -Eo '([A-Z][A-Za-z]+\s([A-Za-z ]+)*)' | head -n1)
title=$(curl -sSL "$*" | tr '<' '<\n' | \grep title -A 1 | head -n1 | sed -E 's/.*<title>(.*)<\/title>.*/\1/' | sed "s/ [^[:alnum:]]*$author//") title=$(curl -sSL "$*" | tr '<' '<\n' | \grep title -A 1 | head -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" ] if [ ! -z "$author" ]; then
then
echo "by $author" echo "by $author"
fi fi
if [ ! -z "$title" ] if [ ! -z "$title" ]; then
then
echo "-> $title" echo "-> $title"
fi fi
if [[ $yearint -ge 1970 && $yearint -le $currentyear ]] if [[ $yearint -ge 1970 && $yearint -le $currentyear ]]; then
then
echo "$yearint" echo "$yearint"
fi fi
if [ ! -z "$title" ] && [ ! -z "$author" ] && [[ $yearint -ge 1970 && $yearint -le $currentyear ]]; then if [ ! -z "$title" ] && [ ! -z "$author" ] && [[ $yearint -ge 1970 && $yearint -le $currentyear ]]; then
@ -174,7 +170,7 @@ function col() {
} }
# Skip first x words in line # Skip first x words in line
# via https://blog.developer.atlassian.com/ten-tips-for-wonderful-bash-productivity/ # via https://blog.developer.atlassian.com/ten-tips-for-wonderful-bash-productivity/
function skip { function skip() {
n=$(($1 + 1)) n=$(($1 + 1))
cut -d' ' -f$n- cut -d' ' -f$n-
} }
@ -199,12 +195,12 @@ 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 -u | 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 -nr | head -50"
} }
@ -227,7 +223,8 @@ function meteo() {
curl "fr.wttr.in/$*" curl "fr.wttr.in/$*"
} }
function how_in() { function how_in() {
where="$1"; shift where="$1"
shift
IFS=+ curl "cht.sh/${where}/$*" IFS=+ curl "cht.sh/${where}/$*"
} }
function rate() { function rate() {
@ -235,8 +232,7 @@ function rate() {
} }
function transfer() { function transfer() {
# check arguments # check arguments
if [ $# -eq 0 ]; if [ $# -eq 0 ]; then
then
warning "No arguments specified. Usage:\necho transfer /tmp/test.md\ncat /tmp/test.md | transfer test.md" warning "No arguments specified. Usage:\necho transfer /tmp/test.md\ncat /tmp/test.md | transfer test.md"
return 1 return 1
fi fi
@ -247,18 +243,15 @@ function transfer() {
# upload stdin or file # upload stdin or file
file=$1 file=$1
if tty -s; if tty -s; then
then
basefile=$(basename "$file" | sed -e 's/[^a-zA-Z0-9._-]/-/g') basefile=$(basename "$file" | sed -e 's/[^a-zA-Z0-9._-]/-/g')
if [ ! -e $file ]; if [ ! -e $file ]; then
then
error "File $file doesn't exists." error "File $file doesn't exists."
return 1 return 1
fi fi
if [ -d $file ]; if [ -d $file ]; then
then
# zip directory and transfer # zip directory and transfer
zipfile=$(mktemp -t transferXXX.zip) zipfile=$(mktemp -t transferXXX.zip)
cd $(dirname $file) && zip -r -q - $(basename $file) >>$zipfile cd $(dirname $file) && zip -r -q - $(basename $file) >>$zipfile
@ -285,27 +278,27 @@ function whichfunc() {
} }
# git shortcuts # git shortcuts
function gcrb { function gcrb() {
branch=$1 branch=$1
git checkout -b $branch origin/$branch git checkout -b $branch origin/$branch
} }
function terraform-compliance { docker run --rm -v "$(pwd):/target" -i -t eerkunt/terraform-compliance "$@"; } function terraform-compliance() { docker run --rm -v "$(pwd):/target" -i -t eerkunt/terraform-compliance "$@"; }
function checkov { docker run -i --rm -v "$(pwd):/tf" bridgecrew/checkov -d /tf "$@" ; } function checkov() { docker run -i --rm -v "$(pwd):/tf" bridgecrew/checkov -d /tf "$@"; }
function vimat { function vimat() {
vim +/$1 $2 vim +/$1 $2
} }
function installhooks { function installhooks() {
pre-commit install --install-hooks --overwrite --allow-missing-config pre-commit install --install-hooks --overwrite --allow-missing-config
} }
function copyhooks { function copyhooks() {
cp -f ~/.git-template/.pre-commit-config.yaml ./ cp -f ~/.git-template/.pre-commit-config.yaml ./
installhooks; installhooks
runhooks; runhooks
} }
function httperr { function httperr() {
curl -s "https://http.cat/$1" | imgcat curl -s "https://http.cat/$1" | imgcat
} }
function terragrunt_color { function terragrunt_color() {
BOLD=$(tput bold) BOLD=$(tput bold)
BLACK=$(tput setaf 0) BLACK=$(tput setaf 0)
RED=$(tput setaf 1) RED=$(tput setaf 1)
@ -331,9 +324,7 @@ function terragrunt_color {
-e "s/\( *.*: *\".*\"\)/${GREEN}\1${RESET}/" -e "s/\( *.*: *\".*\"\)/${GREEN}\1${RESET}/"
} }
function git-project() {
function git-project {
if [ -d "$REPO_PATH" ]; then if [ -d "$REPO_PATH" ]; then
REPO_PATH="$(pwd)" REPO_PATH="$(pwd)"
fi fi
@ -343,36 +334,35 @@ function git-project {
cd "$dir" || exit cd "$dir" || exit
fi fi
} }
function jenkins-cli { function jenkins-cli() {
local script_location=$(find $HOME/code/jenkins-cloudbees-core -name "jenkins-cli.sh") local script_location=$(find $HOME/code/jenkins-cloudbees-core -name "jenkins-cli.sh")
eval "$script_location $*" eval "$script_location $*"
} }
function passwords { function passwords() {
bw list items --search "$1" | jq -c '.[] | .name + " " + .login.username + ":" + .login.password + " " + .login.uris[0].uri' bw list items --search "$1" | jq -c '.[] | .name + " " + .login.username + ":" + .login.password + " " + .login.uris[0].uri'
} }
function password { 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 -Eo "^[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
} }
function setorigin { function setorigin() {
gra origin "$1" 2>/dev/null gra origin "$1" 2>/dev/null
grset origin "$1" grset origin "$1"
if [[ $string =~ "collibra" ]]; then if [[ $string =~ "$COMPANY_NAME" ]]; then
copyhooks copyhooks
fi fi
} }
function gitpushcurrentremote { function gitpushcurrentremote() {
gitpushallremote "$(git_current_branch)" gitpushallremote "$(git_current_branch)"
} }
function gitpushallremote { function gitpushallremote() {
local param_branch="$1" local param_branch="$1"
grv grv
grv | grep push | awk '{print $1}' | while read -r remote grv | grep push | awk '{print $1}' | while read -r remote; do
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" git push --all "$remote"
@ -382,13 +372,13 @@ function gitpushallremote {
fi fi
done done
} }
function clone { function clone() {
local folder=$(basename $1 | sed 's/\.git.*//g') local folder=$(basename $1 | sed 's/\.git.*//g')
arrow "git project identified as $folder" arrow "git project identified as $folder"
if gcls "$1"; then if gcls "$1"; then
if [[ -n "$folder" ]]; then if [[ -n "$folder" ]]; then
cd "$folder" || exit cd "$folder" || exit
if [[ $string =~ "collibra" ]]; then if [[ "$string:u" =~ "$COMPANY_NAME:u" ]]; then
copyhooks copyhooks
fi fi
else else
@ -398,7 +388,7 @@ function clone {
error "unable to clone repository url : $1" error "unable to clone repository url : $1"
fi fi
} }
function colorpic { function colorpic() {
local picture_url="$1" local picture_url="$1"
arrow "Colorizing $picture_url" arrow "Colorizing $picture_url"
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)
@ -406,36 +396,36 @@ function colorpic {
arrow "Display in progress..." arrow "Display in progress..."
eval "\curl -s $result_url | imgcat" eval "\curl -s $result_url | imgcat"
} }
function brewadd { function brewadd() {
brew install "$1" brew install "$1"
ansible 127.0.0.1 -m lineinfile -a "path=~/Brewfile line='brew \"$1\"'" ansible 127.0.0.1 -m lineinfile -a "path=~/Brewfile line='brew \"$1\"'"
} }
function pipadd { function pipadd() {
pip install "$1" pip install "$1"
pip freeze >"$HOME/requirements.txt" pip freeze >"$HOME/requirements.txt"
} }
function goadd { function goadd() {
ansible 127.0.0.1 -m lineinfile -a "path=~/.scripts/godeps.sh line='go get -u -v $1'" ansible 127.0.0.1 -m lineinfile -a "path=~/.scripts/godeps.sh line='go get -u -v $1'"
go get -u -v "$1" go get -u -v "$1"
} }
function rssadd { function rssadd() {
ansible 127.0.0.1 -m lineinfile -a "path=~/.newsboat/urls line='"$1"'" ansible 127.0.0.1 -m lineinfile -a "path=~/.newsboat/urls line='"$1"'"
newsboat newsboat
} }
function bookmarkadd { function bookmarkadd() {
ansible 127.0.0.1 -m lineinfile -a "path=$HOME/Code/bookmarks/README.md insertafter='"$1"' line='* "$2"'" ansible 127.0.0.1 -m lineinfile -a "path=$HOME/Code/bookmarks/README.md insertafter='"$1"' line='* "$2"'"
} }
function backupgithub { function backupgithub() {
curl -sL "https://api.github.com/users/$1/repos" | jq -r '.[] | .ssh_url' | xargs -n1 git clone --mirror --no-hardlinks curl -sL "https://api.github.com/users/$1/repos" | jq -r '.[] | .ssh_url' | xargs -n1 git clone --mirror --no-hardlinks
} }
# Make a directory and cd to it # Make a directory and cd to it
function take { function take() {
mkdir -p $@ && cd ${@:$#} mkdir -p $@ && cd ${@:$#}
} }
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 -Eo "Working until ([0-9:]+) will make.*" | uniq | \grep -Eo "([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 -Eo "Clock out.*([0-9:]+)" | \grep -Eo "([0-9]+:[0-9]+)")
max_hour="$clockout" max_hour="$clockout"
@ -448,13 +438,13 @@ function endofday {
moro report moro report
fi fi
} }
function convtimetodate { function convtimetodate() {
date -j -f '%H:%M' "$1" +'%Y/%m/%d %H:%M' date -j -f '%H:%M' "$1" +'%Y/%m/%d %H:%M'
} }
function convtimetotimestamp { function convtimetotimestamp() {
date -j -f '%H:%M' "$1" +'%s' date -j -f '%H:%M' "$1" +'%s'
} }
function is_earlier { function is_earlier() {
local first=$(convtimetotimestamp "$1") local first=$(convtimetotimestamp "$1")
local second=$(convtimetotimestamp "$2") local second=$(convtimetotimestamp "$2")
if [ "$second" -gt "$first" ]; then if [ "$second" -gt "$first" ]; then
@ -463,32 +453,32 @@ function is_earlier {
false false
fi fi
} }
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" git show "HEAD:$path_to_file" | colordiff -y - "$path_to_file"
} }
function dl_stopwords { function dl_stopwords() {
curl -Lks https://raw.githubusercontent.com/MorganGeek/bookmarks/master/stopwords.txt -o "$HOME/stopwords.txt" curl -Lks 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 | uniq -c | sort --numeric-sort --reverse \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 | uniq -c | sort --numeric-sort --reverse
} }
function file_getpairs { function file_getpairs() {
dl_stopwords; dl_stopwords
\cat "$1" | tr '[:upper:]' '[:lower:]' | \grep -o -E '\w{3,} \w{3,}' | \grep --invert-match --word-regexp --fixed-strings --file="$HOME/stopwords.txt" | \sed 's/s$//g' | \sed 's/ing$//g' | sort | uniq -c | sort --numeric-sort --reverse \cat "$1" | tr '[:upper:]' '[:lower:]' | \grep -o -E '\w{3,} \w{3,}' | \grep --invert-match --word-regexp --fixed-strings --file="$HOME/stopwords.txt" | \sed 's/s$//g' | \sed 's/ing$//g' | sort | uniq -c | sort --numeric-sort --reverse
} }
function file_dups { function file_dups() {
\cat "$1" | sort | uniq -c | sort -nr \cat "$1" | sort | uniq -c | sort -nr
} }
function foreach_run { function foreach_run() {
find . -name "$1" -exec "$2" {} \; find . -name "$1" -exec "$2" {} \;
} }
# input should be something like : 1-10 to generate one number between 1 and 10 # input should be something like : 1-10 to generate one number between 1 and 10
function chance { function chance() {
[[ $(shuf -i "$1" -n 1) == 1 ]] [[ $(shuf -i "$1" -n 1) == 1 ]]
} }
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" && compgen -A function "$1" 1>/dev/null); then if alias "$1" 2>/dev/null || (compgen -A function | grep "$1" && compgen -A function "$1" 1>/dev/null); then
eval "$1" eval "$1"

View File

@ -131,6 +131,11 @@ export COLORPIC_APIKEY=""
export VAULT_PASSWORD_FILE="" export VAULT_PASSWORD_FILE=""
export DEFAULT_BROWSER=${DEFAULT_BROWSER:-'Google Chrome'} export DEFAULT_BROWSER=${DEFAULT_BROWSER:-'Google Chrome'}
export TRELLO_BOARD_URL="" export TRELLO_BOARD_URL=""
export COMPANY_NAME=""
export GIT_PERSONAL_EMAIL=""
export GIT_PERSONAL_USER=""
export GIT_PRO_EMAIL=""
export GIT_PRO_USER=""
if test -f "$HOME/.scripts/secrets.sh"; then if test -f "$HOME/.scripts/secrets.sh"; then
chmod +x "$HOME/.scripts/secrets.sh" chmod +x "$HOME/.scripts/secrets.sh"