From c87357bb57b905e15c51e0ee22c3c1e2d8648056 Mon Sep 17 00:00:00 2001 From: Brian Zalewski Date: Fri, 28 Oct 2022 04:22:57 +0000 Subject: [PATCH] Update dotfiles/.profile, dotfiles/.bashrc, dotfiles/.zshrc --- dotfiles/.bashrc | 30 --------- dotfiles/.profile | 165 ++++++++++++++++++++++++++++------------------ dotfiles/.zshrc | 75 +++++++-------------- 3 files changed, 124 insertions(+), 146 deletions(-) diff --git a/dotfiles/.bashrc b/dotfiles/.bashrc index 9e33d0b4..de827004 100644 --- a/dotfiles/.bashrc +++ b/dotfiles/.bashrc @@ -177,36 +177,6 @@ export LESS_TERMCAP_us=$'\e[1;4;31m' export LESSHISTFILE=- ### Functions -glog() { - setterm -linewrap off 2>/dev/null - - git --no-pager log --all --color=always --graph --abbrev-commit --decorate --date-order \ - --format=format:'%C(bold blue)%h%C(reset) - %C(bold green)(%ar)%C(reset) %s%C(reset) %C(dim white)- %an%C(reset)%C(bold yellow)%d%C(reset)' "$@" | - sed -E \ - -e 's/\|(\x1b\[[0-9;]*m)+\\(\x1b\[[0-9;]*m)+ /├\1─╮\2/' \ - -e 's/(\x1b\[[0-9;]+m)\|\x1b\[m\1\/\x1b\[m /\1├─╯\x1b\[m/' \ - -e 's/\|(\x1b\[[0-9;]*m)+\\(\x1b\[[0-9;]*m)+/├\1╮\2/' \ - -e 's/(\x1b\[[0-9;]+m)\|\x1b\[m\1\/\x1b\[m/\1├╯\x1b\[m/' \ - -e 's/╮(\x1b\[[0-9;]*m)+\\/╮\1╰╮/' \ - -e 's/╯(\x1b\[[0-9;]*m)+\//╯\1╭╯/' \ - -e 's/(\||\\)\x1b\[m (\x1b\[[0-9;]*m)/╰╮\2/' \ - -e 's/(\x1b\[[0-9;]*m)\\/\1╮/g' \ - -e 's/(\x1b\[[0-9;]*m)\//\1╯/g' \ - -e 's/^\*|(\x1b\[m )\*/\1⎬/g' \ - -e 's/(\x1b\[[0-9;]*m)\|/\1│/g' | - command less -r "$([ $# -eq 0 ] && echo "+/[^/]HEAD")" - - setterm -linewrap on 2>/dev/null -} - -find() { - if [ $# = 1 ]; then - # shellcheck disable=SC2145 - command find . -iname "*$@*" - else - command find "$@" - fi -} rgafzf() { RG_PREFIX="rga --files-with-matches" diff --git a/dotfiles/.profile b/dotfiles/.profile index 5a84311a..c4dfa037 100644 --- a/dotfiles/.profile +++ b/dotfiles/.profile @@ -1,60 +1,74 @@ +# shellcheck disable=SC1090,SC1091 + # Easy file sharing from the command line, using transfer.sh transfer() { if [ $# -eq 0 ]; then - echo -e "No arguments specified.\nUsage:\n transfer \n ... | transfer ">&2; - return 1; - fi; - if tty -s;then - file="$1"; - file_name=$(basename "$file"); - if [ ! -e "$file" ];then - echo "$file: No such file or directory">&2; - return 1; - fi; - if [ -d "$file" ];then - file_name="$file_name.zip" ,; - (cd "$file"&&zip -r -q - .)|curl --progress-bar --upload-file "-" "https://transfer.sh/$file_name"|tee /dev/null,; + echo -e "No arguments specified.\nUsage:\n transfer \n ... | transfer " >&2 + return 1 + fi + if tty -s; then + file="$1" + file_name=$(basename "$file") + if [ ! -e "$file" ]; then + echo "$file: No such file or directory" >&2 + return 1 + fi + if [ -d "$file" ]; then + file_name="$file_name.zip" + (cd "$file" && zip -r -q - .) | curl --progress-bar --upload-file "-" "https://transfer.sh/$file_name" | tee /dev/null, else - cat "$file"|curl --progress-bar --upload-file "-" "https://transfer.sh/$file_name"|tee /dev/null; - fi; + curl --progress-bar --upload-file "-" "https://transfer.sh/$file_name" <"$file" | tee /dev/null + fi else - file_name=$1; - curl --progress-bar --upload-file "-" "https://transfer.sh/$file_name"|tee /dev/null; - fi; + file_name=$1 + curl --progress-bar --upload-file "-" "https://transfer.sh/$file_name" | tee /dev/null + fi } # Install WebDriverAgent on iOS device appiumwebdriver() { - read -p "Enter the UDID of the device you wish to install WebDriverAgent on: " UDID_INPUT - mkdir -p Resources/WebDriverAgent.bundle - bash ./Scripts/bootstrap.sh -d - cd /Applications/Appium.app/Contents/Resources/app/node_modules/appium/node_modules/appium-webdriveragent - xcodebuild -project WebDriverAgent.xcodeproj -scheme WebDriverAgentRunner -destination 'id=${UDID_INPUT}' test + # read -r "Enter the UDID of the device you wish to install WebDriverAgent on: " UDID_INPUT + mkdir -p Resources/WebDriverAgent.bundle + bash ./Scripts/bootstrap.sh -d + cd /Applications/Appium.app/Contents/Resources/app/node_modules/appium/node_modules/appium-webdriveragent || return + xcodebuild -project WebDriverAgent.xcodeproj -scheme WebDriverAgentRunner -destination "id=${UDID_INPUT}" test } # Change directories and view contents at the same time cl() { - DIR="$*"; - # if no DIR given, go home - if [ $# -lt 1 ]; then - DIR=$HOME; - fi; - builtin cd "${DIR}" && \ + DIR="$*" + # if no DIR given, go home + if [ $# -lt 1 ]; then + DIR=$HOME + fi + builtin cd "${DIR}" && # use your preferred ls command - ls -F --color=auto + ls -F --color=auto } # Checks status of a website on downforeveryoneorjustme.com down4me() { - curl -s "http://www.downforeveryoneorjustme.com/$1" | sed '/just you/!d;s/<[^>]*>//g'; + curl -s "http://www.downforeveryoneorjustme.com/$1" | sed '/just you/!d;s/<[^>]*>//g' } -# GAM - a command-line tool for Google Workspace. This alias will run gam or install gam if it is not already installed. -gam() { - if command -v gam > /dev/null; then - gam "$@" +# GAM - a command-line tool for Google Workspace. This alias will run gam or install gam if it is not already installed. Includes type check in case gam is aliased for git. +if ! type gam &>/dev/null; then + gam() { + if command -v gam >/dev/null; then + gam "$@" + else + TMP="$(mktemp)" && curl -sSL https://git.io/install-gam >"$TMP" && bash "$TMP" + gam "$" + fi + } +fi + +find() { + if [ $# = 1 ]; then + # shellcheck disable=SC2145 + command find . -iname "*$@*" else - TMP="$(mktemp)" && curl -sSL https://git.io/install-gam > "$TMP" && bash "$TMP" + command find "$@" fi } @@ -63,49 +77,71 @@ gitopen() { git remote -v | head -n 1 | awk -F "@" '{print $2}' | awk -F " " '{print $1}' | sed 's/:/\//g' | sed 's/.git//g' | awk '{print "http://"$1}' | xargs open } +glog() { + setterm -linewrap off 2>/dev/null + + git --no-pager log --all --color=always --graph --abbrev-commit --decorate --date-order \ + --format=format:'%C(bold blue)%h%C(reset) - %C(bold green)(%ar)%C(reset) %s%C(reset) %C(dim white)- %an%C(reset)%C(bold yellow)%d%C(reset)' "$@" | + sed -E \ + -e 's/\|(\x1b\[[0-9;]*m)+\\(\x1b\[[0-9;]*m)+ /├\1─╮\2/' \ + -e 's/(\x1b\[[0-9;]+m)\|\x1b\[m\1\/\x1b\[m /\1├─╯\x1b\[m/' \ + -e 's/\|(\x1b\[[0-9;]*m)+\\(\x1b\[[0-9;]*m)+/├\1╮\2/' \ + -e 's/(\x1b\[[0-9;]+m)\|\x1b\[m\1\/\x1b\[m/\1├╯\x1b\[m/' \ + -e 's/╮(\x1b\[[0-9;]*m)+\\/╮\1╰╮/' \ + -e 's/╯(\x1b\[[0-9;]*m)+\//╯\1╭╯/' \ + -e 's/(\||\\)\x1b\[m (\x1b\[[0-9;]*m)/╰╮\2/' \ + -e 's/(\x1b\[[0-9;]*m)\\/\1╮/g' \ + -e 's/(\x1b\[[0-9;]*m)\//\1╯/g' \ + -e 's/^\*|(\x1b\[m )\*/\1⎬/g' \ + -e 's/(\x1b\[[0-9;]*m)\|/\1│/g' | + command less -r "$([ $# -eq 0 ] && echo "+/[^/]HEAD")" + + setterm -linewrap on 2>/dev/null +} + # Open Mac OS X desktop on a Linux machine macosx() { - docker run -it --device /dev/kvm -p 50922:10022 -v /tmp/.X11-unix:/tmp/.X11-unix -e "DISPLAY=${DISPLAY:-:0.0}" sickcodes/docker-osx:big-sur + docker run -it --device /dev/kvm -p 50922:10022 -v /tmp/.X11-unix:/tmp/.X11-unix -e "DISPLAY=${DISPLAY:-:0.0}" sickcodes/docker-osx:big-sur } # Run the quickstart script quickstart() { - if command -v qvm-run > /dev/null; then - qvm-run --pass-io personal "curl -sSL https://install.doctor/qubes" > "$HOME/setup.sh" && bash "$HOME/setup.sh" + if command -v qvm-run >/dev/null; then + qvm-run --pass-io personal "curl -sSL https://install.doctor/qubes" >"$HOME/setup.sh" && bash "$HOME/setup.sh" elif [ -d '/Applications' ] && [ -d '/Users' ] && [ -d '/Library' ]; then - curl -sSL https://install.doctor/quickstart > "$HOME/setup.sh" && bash "$HOME/setup.sh" + curl -sSL https://install.doctor/quickstart >"$HOME/setup.sh" && bash "$HOME/setup.sh" elif [ -f '/etc/os-release' ]; then - curl -sSL https://install.doctor/quickstart > "$HOME/setup.sh" && bash "$HOME/setup.sh" + curl -sSL https://install.doctor/quickstart >"$HOME/setup.sh" && bash "$HOME/setup.sh" fi rm -f "$HOME/setup.sh" } # Generate a random string of X length randomstring() { - if [ -z "$1" ]; then - head /dev/urandom | tr -dc A-Za-z0-9 | head -c $1 ; echo '' - else - echo "Pass the number of characters you would like the string to be. Example: randomstring 14" - fi + if [ -z "$1" ]; then + head /dev/urandom | tr -dc A-Za-z0-9 | head -c "$1" + else + echo "Pass the number of characters you would like the string to be. Example: randomstring 14" + fi } # Reset Docker to factory settings resetdocker() { - set +e - CONTAINER_COUNT=$(docker ps -a -q | wc -l) - if [ "$CONTAINER_COUNT" -gt 0 ]; then - docker stop $(docker ps -a -q) - docker rm $(docker ps -a -q) - fi - VOLUME_COUNT=$(docker volume ls -q | wc -l) - if [ "$VOLUME_COUNT" -gt 0 ]; then - docker volume rm $(docker volume ls -q) - fi - NETWORK_COUNT=$(docker network ls -q | wc -l) - if [ "$NETWORK_COUNT" -gt 0 ]; then - docker network rm $(docker network ls -q) - fi - docker system prune -a --force + set +e + CONTAINER_COUNT="$(docker ps -a -q | wc -l)" + if [ "$CONTAINER_COUNT" -gt 0 ]; then + docker stop "$(docker ps -a -q)" + docker rm "$(docker ps -a -q)" + fi + VOLUME_COUNT="$(docker volume ls -q | wc -l)" + if [ "$VOLUME_COUNT" -gt 0 ]; then + docker volume rm "$(docker volume ls -q)" + fi + NETWORK_COUNT="$(docker network ls -q | wc -l)" + if [ "$NETWORK_COUNT" -gt 0 ]; then + docker network rm "$(docker network ls -q)" + fi + docker system prune -a --force } ### Aliases @@ -254,16 +290,17 @@ if [ -e /home/linuxbrew/.linuxbrew/bin/brew ]; then export INFOPATH="/home/linuxbrew/.linuxbrew/share/info:${INFOPATH:-}" fi -if command -v brew > /dev/null; then +if command -v brew >/dev/null; then ### Go export GOPATH="${HOME}/.local/go" - export GOROOT="$(brew --prefix golang)/libexec" + GOROOT="$(brew --prefix golang)/libexec" + export GOROOT export GO111MODULE=on export PATH="$PATH:${GOPATH}/bin:${GOROOT}/bin" ### ASDF if [ -f "$(brew --prefix asdf)/libexec/asdf.sh" ]; then - . $(brew --prefix asdf)/libexec/asdf.sh + . "$(brew --prefix asdf)/libexec/asdf.sh" fi fi diff --git a/dotfiles/.zshrc b/dotfiles/.zshrc index a4687175..52a554fe 100644 --- a/dotfiles/.zshrc +++ b/dotfiles/.zshrc @@ -1,3 +1,6 @@ +#!/usr/bin/env zsh +# shellcheck disable=SC1090,SC1091,SC2034,SC2154,SC2296 + ### Powerline if [[ -r "${XDG_CACHE_HOME:-$HOME/.cache}/p10k-instant-prompt-${(%):-%n}.zsh" ]]; then source "${XDG_CACHE_HOME:-$HOME/.cache}/p10k-instant-prompt-${(%):-%n}.zsh" @@ -104,6 +107,7 @@ zstyle ':completion:*' rehash true zstyle ':completion:*' select-prompt %SScrolling active: current selection at %p%s zstyle ':completion:*' use-compctl false zstyle ':completion:*' verbose true +# shellcheck disable=SC2016 zstyle ':completion:*:kill:*' command 'ps -u $USER -o pid,%cpu,tty,cputime,cmd' # Key bindings @@ -147,7 +151,9 @@ export LESSHISTFILE=- # If this is an xterm set the title to user@host:dir case "$TERM" in xterm*|rxvt*|Eterm|aterm|kterm|gnome*|alacritty) - precmd() { print -Pnr -- $'\e]0;%n@%m: %~\a' } + precmd() { + print -Pnr -- $'\e]0;%n@%m: %~\a' + } ;; esac @@ -164,8 +170,7 @@ export LC_ALL="en_US.UTF-8" # Plugin source helper _source_plugin() { local plugin_name="$1" - for basedir in /usr/share/zsh/plugins /usr/share - do + for basedir in /usr/share/zsh/plugins /usr/share; do plugin="$basedir/$plugin_name/$plugin_name.zsh" [ -f "$plugin" ] && source "$plugin" && return 0 done @@ -227,8 +232,7 @@ unset -f _source_plugin # POWERLEVEL if ! [[ $(tty) = /dev/tty* ]] then - if source /usr/share/zsh-theme-powerlevel10k/powerlevel10k.zsh-theme 2> /dev/null - then + if source /usr/share/zsh-theme-powerlevel10k/powerlevel10k.zsh-theme 2> /dev/null; then s=' ' # fix too wide icons POWERLEVEL9K_MODE=nerdfont-complete POWERLEVEL9K_SHORTEN_STRATEGY=truncate_beginning @@ -236,6 +240,7 @@ then POWERLEVEL9K_PROMPT_ON_NEWLINE=true POWERLEVEL9K_RPROMPT_ON_NEWLINE=true POWERLEVEL9K_SHORTEN_DIR_LENGTH=2 + # shellcheck disable=SC2016 POWERLEVEL9K_OS_ICON_CONTENT_EXPANSION='${P9K_CONTENT} $(whoami | grep -v "^root\$")' POWERLEVEL9K_OS_ICON_BACKGROUND=red POWERLEVEL9K_OS_ICON_FOREGROUND=white @@ -310,54 +315,21 @@ switch_powerlevel_multiline_prompt(){ zle -N switch_powerlevel_multiline_prompt bindkey ^P switch_powerlevel_multiline_prompt - -# -------------------------------- FUNCTIONS --------------------------------- -glog() { - setterm -linewrap off 2> /dev/null - - git --no-pager log --all --color=always --graph --abbrev-commit --decorate --date-order \ - --format=format:'%C(bold blue)%h%C(reset) - %C(bold green)(%ar)%C(reset) %s%C(reset) %C(dim white)- %an%C(reset)%C(bold yellow)%d%C(reset)' "$@" \ - | sed -E \ - -e 's/\|(\x1b\[[0-9;]*m)+\\(\x1b\[[0-9;]*m)+ /├\1─╮\2/' \ - -e 's/(\x1b\[[0-9;]+m)\|\x1b\[m\1\/\x1b\[m /\1├─╯\x1b\[m/' \ - -e 's/\|(\x1b\[[0-9;]*m)+\\(\x1b\[[0-9;]*m)+/├\1╮\2/' \ - -e 's/(\x1b\[[0-9;]+m)\|\x1b\[m\1\/\x1b\[m/\1├╯\x1b\[m/' \ - -e 's/╮(\x1b\[[0-9;]*m)+\\/╮\1╰╮/' \ - -e 's/╯(\x1b\[[0-9;]*m)+\//╯\1╭╯/' \ - -e 's/(\||\\)\x1b\[m (\x1b\[[0-9;]*m)/╰╮\2/' \ - -e 's/(\x1b\[[0-9;]*m)\\/\1╮/g' \ - -e 's/(\x1b\[[0-9;]*m)\//\1╯/g' \ - -e 's/^\*|(\x1b\[m )\*/\1⎬/g' \ - -e 's/(\x1b\[[0-9;]*m)\|/\1│/g' \ - | command less -r $([ $# -eq 0 ] && echo "+/[^/]HEAD") - - setterm -linewrap on 2> /dev/null -} - -find() { - if [ $# = 1 ] - then - command find . -iname "*$@*" - else - command find "$@" - fi -} - ### Antigen [[ ! -f ~/.local/antigen.zsh ]] || source ~/.local/antigen.zsh if command -v antigen > /dev/null; then - antigen use oh-my-zsh - antigen bundle git - antigen bundle bundler - antigen bundle dotenv - antigen bundle macos - antigen bundle rake - antigen bundle rbenv - antigen bundle ruby - antigen bundle k - antigen bundle marlonrichert/zsh-autocomplete - antigen apply + antigen use oh-my-zsh + antigen bundle git + antigen bundle bundler + antigen bundle dotenv + antigen bundle macos + antigen bundle rake + antigen bundle rbenv + antigen bundle ruby + antigen bundle k + antigen bundle marlonrichert/zsh-autocomplete + antigen apply fi ## TODO @@ -375,15 +347,14 @@ fi ### Google Cloud SDK if command -v brew > /dev/null; then - [[ ! -f "$(brew --prefix)/Caskroom/google-cloud-sdk/latest/google-cloud-sdk/path.zsh.inc" ]] || source "$(brew --prefix)/Caskroom/google-cloud-sdk/latest/google-cloud-sdk/path.zsh.inc" - [[ ! -f "$(brew --prefix)/Caskroom/google-cloud-sdk/latest/google-cloud-sdk/completion.zsh.inc" ]] || source "$(brew --prefix)/Caskroom/google-cloud-sdk/latest/google-cloud-sdk/completion.zsh.inc" + [[ ! -f "$(brew --prefix)/Caskroom/google-cloud-sdk/latest/google-cloud-sdk/path.zsh.inc" ]] || source "$(brew --prefix)/Caskroom/google-cloud-sdk/latest/google-cloud-sdk/path.zsh.inc" + [[ ! -f "$(brew --prefix)/Caskroom/google-cloud-sdk/latest/google-cloud-sdk/completion.zsh.inc" ]] || source "$(brew --prefix)/Caskroom/google-cloud-sdk/latest/google-cloud-sdk/completion.zsh.inc" fi ## TODO: What is this line? fpath+=~/.zfunc ### zoxide -# TODO: Ensure zoxide.vim is installed command -v zoxide > /dev/null && eval "$(zoxide init zsh)" ### Fig