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

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

@ -1,4 +1,28 @@
#!/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() {
local username
username="$(git config --global -l | grep "user.email" | cut -d'@' -f1 | cut -d'=' -f2)"

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

@ -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

@ -2,6 +2,7 @@
export SDKMAN_DIR="$HOME/.sdkman"
[[ -s "$SDKMAN_DIR/bin/sdkman-init.sh" ]] && source "$SDKMAN_DIR/bin/sdkman-init.sh"
# shellcheck disable
# Reload
echo "Reloading config"

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