From fa3dc531a029d043b90d111c7d90eafb35b1e0a6 Mon Sep 17 00:00:00 2001 From: Ismo Vuorinen Date: Mon, 27 Mar 2023 09:51:41 +0300 Subject: [PATCH] Tweaks & EOL's added --- .editorconfig | 3 ++ .gitignore | 2 +- base/huskyrc | 1 + base/zshrc | 16 ++++---- config/exports | 10 ++++- config/functions | 1 + hosts/tunkki/bash_logout | 7 ---- hosts/tunkki/bashrc | 1 + hosts/v/config/git/config | 1 + local/bin/dfm | 3 +- local/bin/git-dirty | 1 + local/bin/x-backup-mysql-with-prefix.sh | 5 ++- local/bin/x-check-git-attributes | 3 +- local/bin/x-dupes.pl | 1 + local/bin/x-foreach | 1 + local/bin/x-multi-ping.pl | 1 + local/bin/x-open-ports | 2 + local/bin/x-ssl-expiry-date | 53 ++++++------------------- local/bin/x-until-error | 6 +-- local/bin/x-until-success | 11 ++--- local/bin/x-validate-sha256sum.sh | 1 + local/bin/x-when-down | 3 +- local/bin/x-when-up | 9 +++-- scripts/install-npm-packages.sh | 1 + scripts/set-macos-defaults.sh | 1 + scripts/shared.sh | 5 ++- 26 files changed, 70 insertions(+), 79 deletions(-) delete mode 100644 hosts/tunkki/bash_logout diff --git a/.editorconfig b/.editorconfig index e3edfc9..c69da21 100644 --- a/.editorconfig +++ b/.editorconfig @@ -8,6 +8,9 @@ indent_style = space insert_final_newline = true trim_trailing_whitespace = true +[*.lua] +insert_final_newline = true + [*.yaml,*.yml] indent_size = 2 insert_final_newline = true diff --git a/.gitignore b/.gitignore index fa8f846..0172937 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,3 @@ Brewfile.lock.json *.log - +*-secret diff --git a/base/huskyrc b/base/huskyrc index 7173adf..7d30591 100644 --- a/base/huskyrc +++ b/base/huskyrc @@ -5,3 +5,4 @@ export NVM_DIR="$HOME/.nvm" [ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" # This loads nvm bash_completion alias php="php -d error_reporting=22527" + diff --git a/base/zshrc b/base/zshrc index 40640a5..cdbad48 100644 --- a/base/zshrc +++ b/base/zshrc @@ -1,3 +1,4 @@ +# this is my zsh config. there are many like it, but this one is mine. # shellcheck shell=bash autoload -U colors zsh/terminfo @@ -24,15 +25,15 @@ export PATH="$XDG_BIN_HOME:$HOMEBREW_BIN:$HOMEBREW_SBIN:/usr/local/sbin:$PATH" # brew, https://brew.sh if [ command -v brew &> /dev/null ]; then - BREW_BIN=$(brew --prefix)/bin - BREW_SBIN=$(brew --prefix)/sbin + BREW_BIN=$(brew --prefix)/bin + BREW_SBIN=$(brew --prefix)/sbin - BREW_PYTHON=$(brew --prefix python@3.8)/bin - GNUBIN_DIR=$(brew --prefix coreutils)/libexec/gnubin - BREW_RUBY=$(brew --prefix ruby)/bin - BREW_GEMS=$(gem environment gemdir)/bin + BREW_PYTHON=$(brew --prefix python@3.8)/bin + GNUBIN_DIR=$(brew --prefix coreutils)/libexec/gnubin + BREW_RUBY=$(brew --prefix ruby)/bin + BREW_GEMS=$(gem environment gemdir)/bin - export PATH="$BREW_PYTHON:$GNUBIN_DIR:$BREW_GEMS:$BREW_RUBY:$BREW_BIN:$BREW_SBIN:$PATH" + export PATH="$BREW_PYTHON:$GNUBIN_DIR:$BREW_GEMS:$BREW_RUBY:$BREW_BIN:$BREW_SBIN:$PATH" fi # nvm, the node version manager @@ -163,3 +164,4 @@ fi [[ -f "$XDG_BIN_HOME/iterm2_shell_integration.zsh" ]] && source "$XDG_BIN_HOME/iterm2_shell_integration.zsh" eval "$(starship init zsh)" + diff --git a/config/exports b/config/exports index 0fc165e..faf7ebd 100644 --- a/config/exports +++ b/config/exports @@ -5,7 +5,9 @@ export HIST_STAMPS="yyyy-mm-dd" # Larger bash history (allow 32³ entries; default is 500) export HISTSIZE=32768 export HISTFILESIZE=$HISTSIZE -export HISTCONTROL=ignoredups +# don't put duplicate lines or lines starting with space in the history. +# See bash(1) for more options +export HISTCONTROL=ignoreboth # Make some commands not show up in history export HISTIGNORE="ls:cd:cd -:pwd:exit:date:* --help" @@ -21,3 +23,9 @@ export MANPAGER="less -X" # Always enable colored `grep` output export GREP_OPTIONS="--color=auto" + +# check the window size after each command and, if necessary, +# update the values of LINES and COLUMNS. +shopt -s checkwinsize + + diff --git a/config/functions b/config/functions index c7f33ad..66f1c76 100644 --- a/config/functions +++ b/config/functions @@ -65,3 +65,4 @@ function silent { "$@" >&/dev/null } + diff --git a/hosts/tunkki/bash_logout b/hosts/tunkki/bash_logout deleted file mode 100644 index de4f5f7..0000000 --- a/hosts/tunkki/bash_logout +++ /dev/null @@ -1,7 +0,0 @@ -# ~/.bash_logout: executed by bash(1) when login shell exits. - -# when leaving the console clear the screen to increase privacy - -if [ "$SHLVL" = 1 ]; then - [ -x /usr/bin/clear_console ] && /usr/bin/clear_console -q -fi diff --git a/hosts/tunkki/bashrc b/hosts/tunkki/bashrc index b488fcc..a81d389 100644 --- a/hosts/tunkki/bashrc +++ b/hosts/tunkki/bashrc @@ -115,3 +115,4 @@ if ! shopt -oq posix; then . /etc/bash_completion fi fi + diff --git a/hosts/v/config/git/config b/hosts/v/config/git/config index 3d8a7e8..745eb79 100644 --- a/hosts/v/config/git/config +++ b/hosts/v/config/git/config @@ -72,3 +72,4 @@ [submodule] recurse = true + diff --git a/local/bin/dfm b/local/bin/dfm index 3d91b57..9042643 100755 --- a/local/bin/dfm +++ b/local/bin/dfm @@ -124,7 +124,7 @@ function section_dotfiles shfmt) # Format shell scripts according to following rules. find "$DOTFILES" \ - \( -name '*.sh' -or -name '*.zsh' -or -name 'x-*' -or -not '*.pl' \) \ + \( -name '*.sh' -or -name '*.zsh' -or -name 'x-*' \) \ -exec shfmt -fn -l -w -i 2 -ci -sr -bn {} \; msg_done "🎉 dotfiles have been formatted!" ;; @@ -209,3 +209,4 @@ case "$1" in tests) section_tests "$2" ;; *) usage && exit 0 ;; esac + diff --git a/local/bin/git-dirty b/local/bin/git-dirty index 75fed77..873f9c6 100755 --- a/local/bin/git-dirty +++ b/local/bin/git-dirty @@ -80,3 +80,4 @@ trap 'case $? in esac' EXIT gitdirtyrepos "$GIT_DIRTY_DIR" + diff --git a/local/bin/x-backup-mysql-with-prefix.sh b/local/bin/x-backup-mysql-with-prefix.sh index 8e9472f..9ce3819 100755 --- a/local/bin/x-backup-mysql-with-prefix.sh +++ b/local/bin/x-backup-mysql-with-prefix.sh @@ -35,9 +35,10 @@ TIMESTAMP=$(date "+%Y%m%d_%H%M%S") FILENAME_TIMESTAMP="${DATABASE}_${FILENAME}_${TIMESTAMP}.sql" mysqldump \ - ${DATABASE} \ + "${DATABASE}" \ "$( echo "show tables like '${PREFIX}%';" \ - | mysql ${DATABASE} \ + | mysql "${DATABASE}" \ | sed '/Tables_in/d' )" > "${FILENAME_TIMESTAMP}" + diff --git a/local/bin/x-check-git-attributes b/local/bin/x-check-git-attributes index 2d191c8..fa70d2f 100755 --- a/local/bin/x-check-git-attributes +++ b/local/bin/x-check-git-attributes @@ -6,7 +6,7 @@ if ! command -v git &> /dev/null; then echo "git could not be found, please install it first" - exit + exit 1 fi missing_attributes=$(git ls-files | git check-attr -a --stdin | grep "text: auto") @@ -17,3 +17,4 @@ if [[ "$missing_attributes" ]]; then else echo "All files have a corresponding rule in .gitattributes" fi + diff --git a/local/bin/x-dupes.pl b/local/bin/x-dupes.pl index 59d6df5..8b480a9 100755 --- a/local/bin/x-dupes.pl +++ b/local/bin/x-dupes.pl @@ -206,3 +206,4 @@ sub parsedOptions return (%vars); } + diff --git a/local/bin/x-foreach b/local/bin/x-foreach index baf4719..9b8278f 100755 --- a/local/bin/x-foreach +++ b/local/bin/x-foreach @@ -14,3 +14,4 @@ for dir in $($cmd); do eval "$@" # allow multiple commands like "foo && bar" ) done + diff --git a/local/bin/x-multi-ping.pl b/local/bin/x-multi-ping.pl index 5ca62f4..c0134a3 100755 --- a/local/bin/x-multi-ping.pl +++ b/local/bin/x-multi-ping.pl @@ -226,3 +226,4 @@ sub parsedOptions return (%vars); } + diff --git a/local/bin/x-open-ports b/local/bin/x-open-ports index 9691c9d..f042ea4 100755 --- a/local/bin/x-open-ports +++ b/local/bin/x-open-ports @@ -3,6 +3,7 @@ # List open (listened) ports, without the crud that # usually comes with `lsof -i` # +# Modified by: Ismo Vuorinen 2020 # Originally from: https://www.commandlinefu.com/commands/view/8951 # Original author: https://www.commandlinefu.com/commands/by/wickedcpj # @@ -18,3 +19,4 @@ lsof -i 4 -P -n +c 0 \ | uniq echo "" + diff --git a/local/bin/x-ssl-expiry-date b/local/bin/x-ssl-expiry-date index d8c1d70..a300b61 100755 --- a/local/bin/x-ssl-expiry-date +++ b/local/bin/x-ssl-expiry-date @@ -4,37 +4,27 @@ # ----- # Check the expiry date of the SSL certificate on the given host. # -# # License # ------- -# # Copyright (c) 2013-2015 by Steve Kemp. All rights reserved. # # This script is free software; you can redistribute it and/or modify it under # the same terms as Perl itself. # # The LICENSE file contains the full text of the license. -# -# -# -# Simple function to show usage information, and exit. -# +# Simple function to show usage information, and exit. usage() { echo "Usage: $0 [-d] [-p 443] domain1.org domain2.com .. domainN" exit 0 } -# -# Default settings for flags set by the command-line arguments -# +# Default settings for flags set by the command-line arguments days=0 port=443 -# -# Parse the argument(s) - i.e. look for "-d" / "-p 443". -# +# Parse the argument(s) - i.e. look for "-d" / "-p 443". while getopts "h?dp:" opt; do case $opt in h) @@ -53,21 +43,15 @@ while getopts "h?dp:" opt; do done shift $((OPTIND - 1)) -# -# Ensure we have some arguments -# +# Ensure we have some arguments if [ "$#" = "0" ]; then usage fi -# # For each domain-name on the command-line. -# for name in "$@"; do - # - # Make a temporary file - # + # Make a temporary file # Test if we have BSD or GNU version of mktemp if (strings "$(which mktemp)" | grep -q GNU); then # We have the GNU version @@ -77,27 +61,19 @@ for name in "$@"; do tmp=$(mktemp -t tmp) fi - # - # Download the certificate - # - if (! echo "" | openssl s_client -connect $name:$port > $tmp 2> /dev/null); then + # Download the certificate + if (! echo "" | openssl s_client -connect "$name:$port" > "$tmp" 2> /dev/null); then echo "Failed to get cert from https://$name:$port/" exit 3 fi - # - # Get the expiry date - # + # Get the expiry date date=$(openssl x509 -in "$tmp" -noout -enddate | awk -F= '{print $2}') - # - # Remove the temporary file - # + # Remove the temporary file rm -f "$tmp" - # - # Convert the expiry date + todays date to seconds-past epoch - # + # Convert the expiry date + todays date to seconds-past epoch # Check if we have the BSD or the GNU version of date if (strings "$(which date)" | grep -q GNU); then # We have GNU this is easy @@ -115,15 +91,11 @@ for name in "$@"; do now=$(date +%s) - # - # Day diff - # + # Day diff diff=$(("$then" - "$now")) diff=$($diff / 86400) - # - # All done - # + # All done if [ "$days" = "1" ]; then echo "${name}: ${diff}" else @@ -132,3 +104,4 @@ for name in "$@"; do echo " Days: ${diff}" fi done + diff --git a/local/bin/x-until-error b/local/bin/x-until-error index e987eba..26b9e73 100755 --- a/local/bin/x-until-error +++ b/local/bin/x-until-error @@ -3,13 +3,11 @@ # About # ----- # Repeat the command until it fails - always run at least once. -# "$@" -# -# If the status code was zero then repeat. -# +# If the status code was zero then repeat. while [ $? -eq 0 ]; do "$@" done + diff --git a/local/bin/x-until-success b/local/bin/x-until-success index 77d1136..e34a06d 100755 --- a/local/bin/x-until-success +++ b/local/bin/x-until-success @@ -14,17 +14,12 @@ # the same terms as Perl itself. # # The LICENSE file contains the full text of the license. -# -# -# -# Run the first time. -# +# Run the first time. "$@" -# -# If the status code was not zero then repeat. -# +# If the status code was not zero then repeat. while [ $? -ne 0 ]; do "$@" done + diff --git a/local/bin/x-validate-sha256sum.sh b/local/bin/x-validate-sha256sum.sh index 191b25a..579ee6e 100755 --- a/local/bin/x-validate-sha256sum.sh +++ b/local/bin/x-validate-sha256sum.sh @@ -50,3 +50,4 @@ elif [ "$(get_sha256sum "$filename")" = "$file_hash" ]; then else error "$filename doesn't match provided sha256sum" fi + diff --git a/local/bin/x-when-down b/local/bin/x-when-down index 3c04c24..8467b78 100755 --- a/local/bin/x-when-down +++ b/local/bin/x-when-down @@ -24,9 +24,10 @@ echo "Waiting for $HOST to get down..." true while [ $? -ne 1 ]; do - ping -c 1 -W 1 $HOST > /dev/null + ping -c 1 -W 1 "$HOST" > /dev/null done shift "$@" + diff --git a/local/bin/x-when-up b/local/bin/x-when-up index b846626..d4a298f 100755 --- a/local/bin/x-when-up +++ b/local/bin/x-when-up @@ -22,7 +22,7 @@ if [ $# -lt 2 ]; then exit 1 fi -if [ $1 = "ssh" ]; then +if [ "$1" = "ssh" ]; then HOST=$2 else HOST=$1 @@ -30,16 +30,17 @@ fi echo "Waiting for $HOST to come online..." -ping -c 1 -W 1 $HOST > /dev/null +ping -c 1 -W 1 "$HOST" > /dev/null while [ $? -ne 0 ]; do sleep 1 - ping -c 1 -W 1 $HOST > /dev/null + ping -c 1 -W 1 "$HOST" > /dev/null done # By the time we reach here the ping-command has completed successfully # so we can launch the command we were given - along with any arguments. -if [ $1 != "ssh" ]; then +if [ "$1" != "ssh" ]; then shift fi "$@" + diff --git a/scripts/install-npm-packages.sh b/scripts/install-npm-packages.sh index 8a38aac..11136c0 100755 --- a/scripts/install-npm-packages.sh +++ b/scripts/install-npm-packages.sh @@ -36,3 +36,4 @@ else echo "" done fi + diff --git a/scripts/set-macos-defaults.sh b/scripts/set-macos-defaults.sh index 9798b76..c21dd59 100755 --- a/scripts/set-macos-defaults.sh +++ b/scripts/set-macos-defaults.sh @@ -299,3 +299,4 @@ for app in "Activity Monitor" "Address Book" "Calendar" "Contacts" "cfprefsd" \ killall "${app}" > /dev/null 2>&1 done echo "Done. Note that some of these changes require a logout/restart to take effect." + diff --git a/scripts/shared.sh b/scripts/shared.sh index 7cd7701..52540f4 100755 --- a/scripts/shared.sh +++ b/scripts/shared.sh @@ -6,9 +6,9 @@ # -- Colors -- # CLR_RED="\033[1;31m" -CLR_YELLOW='\033[1;33m' +CLR_YELLOW="\033[1;33m" CLR_GREEN="\033[1;32m" -CLR_BLUE='\033[1;34m' +CLR_BLUE="\033[1;34m" CLR_RESET="\033[0m" # -- Helpers -- # @@ -111,3 +111,4 @@ function fn_exists() declare -f -F "$1" > /dev/null return $? } +