From 278be5a6c6ddd4fffa2de0b0b8db9aea0d951714 Mon Sep 17 00:00:00 2001 From: Gal Szkolnik Date: Sun, 23 Oct 2022 18:10:30 -0400 Subject: [PATCH] Added modiciation from a parallel project --- _home/dot_poshtheme.omp.json | 10 +- _home/dot_profile | 27 ++++++ _home/dot_sz.shrc | 44 ++++++++- _home/dot_sz.shrc.d/01_util.functions | 38 ++++++-- _home/dot_sz.shrc.d/02_shlvl | 23 +++++ _home/dot_sz.shrc.d/22_editor.aliases | 27 ------ _home/dot_sz.shrc.d/23_sudo | 1 + _home/dot_sz.shrc.d/28_homebrew | 4 + _home/dot_sz.shrc.d/32_gcp.shortcuts | 91 ++++++++++++++----- _home/dot_sz.shrc.d/81_alacritty_colorscheme | 6 ++ _home/dot_sz.shrc.d/97_chezmoi_aliases | 69 ++++++++++---- .../bash.post/10_oh-my-posh.hook | 4 +- .../99_alacritty-colorscheme.completion | 2 + .../bash.post/99_chezmoi.completion | 10 +- .../bash.pre/10_check_completion | 7 +- _home/dot_sz.shrc.d/bash.pre/21_aliases | 6 +- _home/dot_sz.shrc.d/zsh.pre/21_aliases | 10 +- .../bin/executable_get-github-release.sh | 20 ++++ .../bin/executable_identify-large-git-blobs | 13 +++ .../bin/executable_install-deb-from-web.sh | 15 +++ ...ecutable_launch-teamviewer-quicksupport.sh | 53 ----------- .../bin/executable_sz-doctor | 1 + .../private_dot_local/bin/executable_sz-help | 84 +++++++++++++++++ .../bin/executable_sz-setup-user-env | 70 ++++++++++++++ 24 files changed, 492 insertions(+), 143 deletions(-) create mode 100644 _home/dot_profile create mode 100644 _home/dot_sz.shrc.d/02_shlvl create mode 100644 _home/dot_sz.shrc.d/28_homebrew create mode 100644 _home/dot_sz.shrc.d/81_alacritty_colorscheme create mode 100644 _home/dot_sz.shrc.d/bash.post/99_alacritty-colorscheme.completion create mode 100644 _home/private_dot_local/bin/executable_get-github-release.sh create mode 100644 _home/private_dot_local/bin/executable_identify-large-git-blobs create mode 100644 _home/private_dot_local/bin/executable_install-deb-from-web.sh delete mode 100644 _home/private_dot_local/bin/executable_launch-teamviewer-quicksupport.sh create mode 100644 _home/private_dot_local/bin/executable_sz-help create mode 100644 _home/private_dot_local/bin/executable_sz-setup-user-env diff --git a/_home/dot_poshtheme.omp.json b/_home/dot_poshtheme.omp.json index 6e20364..d42f316 100644 --- a/_home/dot_poshtheme.omp.json +++ b/_home/dot_poshtheme.omp.json @@ -118,6 +118,14 @@ "template": " {{ if .WSL }}WSL at {{ end }}{{.Icon}} ", "type": "os" }, + { + "type": "text", + "foreground": "#d3d7cf", + "background": "black", + "powerline_symbol": "", + "style": "powerline", + "template": "{{ if gt .Env.SHLVL_pqb \"1\" }}{{ .Env.SHLVL_pqb }}{{ end }}" + }, { "type": "command", "foreground": "#d3d7cf", @@ -301,7 +309,7 @@ "style": "powerline", "properties": { "shell": "bash", - "command": "type -t chezmoi 2>&1 >/dev/null && printf \"%s\" $(chezmoi status 2>/dev/null | wc -l) , $(chezmoi git -- status --short | wc -l)" + "command": "type -t chezmoi 2>&1 >/dev/null && printf \"%s\" $(chezmoi status --exclude scripts 2>/dev/null | wc -l) , $(chezmoi git -- status --short | wc -l)" }, "template": "{{ if ne .Output \"0,0\" }}≢{{ .Output }}{{ end }}" }, diff --git a/_home/dot_profile b/_home/dot_profile new file mode 100644 index 0000000..d89ea5a --- /dev/null +++ b/_home/dot_profile @@ -0,0 +1,27 @@ +# ~/.profile: executed by the command interpreter for login shells. +# This file is not read by bash(1), if ~/.bash_profile or ~/.bash_login +# exists. +# see /usr/share/doc/bash/examples/startup-files for examples. +# the files are located in the bash-doc package. + +# the default umask is set in /etc/profile; for setting the umask +# for ssh logins, install and configure the libpam-umask package. +#umask 022 + +# if running bash +if [ -n "$BASH_VERSION" ]; then + # include .bashrc if it exists + if [ -f "$HOME/.bashrc" ]; then + . "$HOME/.bashrc" + fi +fi + +# set PATH so it includes user's private bin if it exists +if [ -d "$HOME/bin" ] ; then + PATH="$HOME/bin:$PATH" +fi + +# set PATH so it includes user's private bin if it exists +if [ -d "$HOME/.local/bin" ] ; then + PATH="$HOME/.local/bin:$PATH" +fi diff --git a/_home/dot_sz.shrc b/_home/dot_sz.shrc index 1b6b1e5..f328fbb 100644 --- a/_home/dot_sz.shrc +++ b/_home/dot_sz.shrc @@ -1,13 +1,53 @@ # If not running interactively, don't do anything SFP='.sz' # Script Family Prefix [ -z ${DBG_SHRC} ] || echo "Entered ${SFP}.shrc" +export SHRC_D=~/${SFP}.shrc.d +unset SHLVL_${SFP##*.} -case $- in +IS_INTERACTIVE=${IS_INTERACTIVE:-$-} +# himBHs - Interactive +# hBc - called with `bash -c` +# Legend: +# h Locate and remember (hash) commands as they are looked up for +# execution. This option is enabled by default. +# i Interactive shell. +# m Job control is enabled (see Job Control). All processes run in a +# separate process group. When a background job completes, the +# shell prints a line containing its exit status. +# c Commands were supplied from via `bash -c` command line switch. +# B The shell will perform brace expansion (see Brace Expansion). +# This option is on by default. +# H Enable ‘!’ style history substitution (see History Interaction). +# This option is on by default for interactive shells. +# s Read commands from the standard input. +export SHRC_D=~/${SFP}.shrc.d +case $IS_INTERACTIVE in + + FORCE) ;; +IS_INTERACTIVE=${IS_INTERACTIVE:-$-} +# himBHs - Interactive +unset IS_INTERACTIVE +# hBc - called with `bash -c` +# h Locate and remember (hash) commands as they are looked up for +# execution. This option is enabled by default. +# i Interactive shell. +# m Job control is enabled (see Job Control). All processes run in a +# separate process group. When a background job completes, the +# shell prints a line containing its exit status. +# c Commands were supplied from via `bash -c` command line switch. +# B The shell will perform brace expansion (see Brace Expansion). +# This option is on by default. +# H Enable ‘!’ style history substitution (see History Interaction). +# This option is on by default for interactive shells. +# s Read commands from the standard input. + +case $IS_INTERACTIVE in *i*) echo "Welcome $USER to $(hostname)";; + FORCE) ;; *) return;; esac +unset IS_INTERACTIVE -export SHRC_D=~/${SFP}.shrc.d if [ -d ${SHRC_D} ]; then script_source=("$(find ${SHRC_D} -maxdepth 1 -type d -name "$(ps -p$$ -ho comm).pre")") script_source+=("$(find ${SHRC_D} -maxdepth 0 -type d)") diff --git a/_home/dot_sz.shrc.d/01_util.functions b/_home/dot_sz.shrc.d/01_util.functions index f811c94..7e8b20e 100644 --- a/_home/dot_sz.shrc.d/01_util.functions +++ b/_home/dot_sz.shrc.d/01_util.functions @@ -1,15 +1,34 @@ +ANSI_Print() { printf "\E[${ANSI_Code}m%s\E[0m" "$@"; } +ANSI_Red() { ANSI_Code=31 ANSI_Print "$@"; } +ANSI_Green() { ANSI_Code=32 ANSI_Print "$@"; } +ANSI_Yellow() { ANSI_Code=33 ANSI_Print "$@"; } +ANSI_Blue() { ANSI_Code=34 ANSI_Print "$@"; } +ANSI_Indiego() { ANSI_Code=35 ANSI_Print "$@"; } +ANSI_Cyan() { ANSI_Code=36 ANSI_Print "$@"; } + warn() { - (>&2 printf '\E[34mWARNING:\E[0m %s\n' "$@" ) + (>&2 printf '%s %s\n' $(ANSI_Yellow 'WARNING:') "$(echo "$@")" ) } +# The way to call this is: +# eval $(error 1 "message") || exit $? +# where 1 is the return/exit code and "message" is the message to be +# displayed error() { - (>&2 printf '\E[31mERROR:\E[0m %s\n' "$@" ) + printf "(>&2 \ + printf '%%s %%b' '$(ANSI_Red 'ERROR:')' '$(printf "%b " "${@:2}")') \ + && echo '' && return ${1} 2>/dev/null || exit ${1}" +} + +require_sudo() { + if [[ $EUID -ne 0 && -z $(printf "%s\n" $(id --groups --name) | grep '^sudo$') ]]; then + eval $(error 1 "This script should be run by a sudo memeber or as the root user") + fi } require_root() { if [[ $EUID -ne 0 ]]; then - error "This script should only be run using sudo or as the root user" - exit 1 + eval $(error 1 "This script should only be run using sudo or as the root user") fi } @@ -22,9 +41,14 @@ recommend_root() { function setacl() { if [[ $# -lt 4 ]]; then - error "setacl missing arguments, called with '$1' ${@:2}" - printf "%s\n" "Usage:" "\tsetacl [...]" - return 1 + eval $(error 1 \ + "setacl missing arguments, called with '$1' ${@:2}" \ + $(printf "%s\n" \ + "Usage:" \ + "\tsetacl [...]" \ + ) + ) + return 1 fi local Options=${1} local Ownership=${2} diff --git a/_home/dot_sz.shrc.d/02_shlvl b/_home/dot_sz.shrc.d/02_shlvl new file mode 100644 index 0000000..bdfc7da --- /dev/null +++ b/_home/dot_sz.shrc.d/02_shlvl @@ -0,0 +1,23 @@ +function shlvl() { + local SHLVL_VAR="SHLVL_${SFP##*.}" + local SHELLS=$( \ + cat /etc/shells \ + | tail +2 \ + | sed 's/.*\///' \ + | sort -u \ + | grep -v tmux \ + | paste -sd '|' \ + ) + local SHLVL_VAL=$(eval "printf '%s' \"\$$SHLVL_VAR\"") + if [[ -z "$SHLVL_VAL" ]]; then + SHLVL_VAL=$(( $( \ + pstree -s $$ \ + | head -1 \ + | sed -r 's/-\+-/---/g; s/-[^-]+---oh-my-posh---.*/-/; s/---/\n/g;' \ + | grep -Ec "^($SHELLS)$" + ) - ${1:-1} )) + eval "export $SHLVL_VAR=$SHLVL_VAL" + fi + echo $SHLVL_VAL +} +shlvl > /dev/null diff --git a/_home/dot_sz.shrc.d/22_editor.aliases b/_home/dot_sz.shrc.d/22_editor.aliases index 6d18ebb..8db5b3a 100644 --- a/_home/dot_sz.shrc.d/22_editor.aliases +++ b/_home/dot_sz.shrc.d/22_editor.aliases @@ -8,34 +8,7 @@ MY_VI="$(type -fP my_vi || printf "%s -p" $(type -fP nvim) || type -fP vi) " [[ -n $(which-command "${EDITOR}") ]] \ && alias my_editor="${EDITOR} " -export DOOMROOT="$HOME/.config/_my.emacs/doom" -[[ -x $DOOMROOT/emacs.d/bin/doom ]] && function doom() { - export EMACSDIR="$DOOMROOT/emacs.d" - export DOOMDIR="$DOOMROOT/config" - "$EMACSDIR/bin/doom" "${@}" - - unset EMACSDIR DOOMDIR -} && function doomemacs() { - emacs --with-profile=doom ${@} -} || unset DOOMROOT - -if [[ -r "$HOME/.config/_my.emacs/spacemacs/emacs.d/init.el" \ - && -n "$(which-command emacsclient)" \ - && -n "$(which-command emacs)" \ - && -n "$(which-command edit-with-spacemacs)" \ - ]]; then - alias my_editor='edit-with-spacemacs' -fi - [[ -n $(which-command my_editor) ]] \ && alias ed="my_editor" \ && alias edit="my_editor" \ && alias editor="my_editor" - -alias nvim="${MY_VI} " -alias vim="${MY_VI} " -alias vi="${MY_VI} " - -alias ed="my_editor" -alias edit="my_editor" -alias editor="my_editor" diff --git a/_home/dot_sz.shrc.d/23_sudo b/_home/dot_sz.shrc.d/23_sudo index f6a10e0..eecd086 100644 --- a/_home/dot_sz.shrc.d/23_sudo +++ b/_home/dot_sz.shrc.d/23_sudo @@ -1,4 +1,5 @@ #alias sudo="/usr/bin/sudo " +alias _sudo="env sudo " function sudo() { local cli="$(command -v "${1}")" [[ -x "$cli" ]] || cli="${1}" diff --git a/_home/dot_sz.shrc.d/28_homebrew b/_home/dot_sz.shrc.d/28_homebrew new file mode 100644 index 0000000..a0609ff --- /dev/null +++ b/_home/dot_sz.shrc.d/28_homebrew @@ -0,0 +1,4 @@ +# Set PATH, MANPATH, etc., for Homebrew. +[[ -x /home/linuxbrew/.linuxbrew/bin/brew ]] && \ + eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv)" + diff --git a/_home/dot_sz.shrc.d/32_gcp.shortcuts b/_home/dot_sz.shrc.d/32_gcp.shortcuts index 7ddb035..81d971d 100644 --- a/_home/dot_sz.shrc.d/32_gcp.shortcuts +++ b/_home/dot_sz.shrc.d/32_gcp.shortcuts @@ -1,25 +1,25 @@ -function gcp_project() { +function gcp-project() { gcloud config get-value core/project 2> /dev/null } -function gcp_get_project_id() { +function gcp-get-project-id() { gcloud projects list \ --filter="$1" \ --format="value(project_id)" \ 2> /dev/null } -function gcp_get_project_number() { +function gcp-get-project-number() { gcloud projects list \ --filter="project_id:$1" \ --format='value(project_number)' \ 2> /dev/null } -function gcp_get_regions() { +function gcp-get-regions() { gcloud compute regions list --format="value(name)" } -function gcp_get_region_quotas() { +function gcp-get-region-quotas() { region_arr_list=( $(gcloud compute regions list --format="value(name)") ) for region in ${region_arr_list[@]}; do @@ -31,34 +31,79 @@ function gcp_get_region_quotas() { #done } -# Usage: gcp_get_stack dragonheart 10 22 +GCP_SUBNETS_FORMAT='--format="table( + name, + region, + network, + ipCidrRange, + stack_type +)"' + +GCP_DISKS_FORMAT='--format="table( + status, + name, + location():label=ZONE, + sizeGb, + type.basename() +)"' + +GCP_INSTANCES_FORMAT='--format="table( + status, + name, + zone, + machineType:label=TYPE, + scheduling.preemptible:label=PREE, + deletionProtection:label=DelPr, + INTERNAL_IP:label=IN_IP, + EXTERNAL_IP:label=EX_IP +)"' + +# Usage: gcp-get-stack dragonheart 10 22 # Watch the 'dragonheart' stack, # refresh every 10 seconds, # set tmux pane to 22 lines high (on every refresh) -function gcp_get_stack() { +function gcp-get-stack() { local N="${1:-$(basename $PWD)}" local _cmd="" local _tmux='' - [ $# -ge 3 ] && [[ -n "$(which-command tmux)" ]] && printf "%s" "$3" > "/tmp/tmux-$1" && _cmd=$(printf "%s" 'tmux resize-pane -t "$TMUX_PANE" -y $(cat "/tmp/tmux-' "$1" '") ; ') && eval $_cmd - _cmd="{ $(printf "%s " \ - "N='$N'; " \ - "${_cmd}" \ - "echo 'Listing $N stack:'; " \ - '{ gcloud compute networks list --filter="name:$N" 2>&1 | ' "sed --unbuffered s/^/Networks.:\ /g ; } " \ - '&& { gcloud compute networks subnets list --filter="name:$N" 2>&1 | ' "sed --unbuffered s/^/Subnets..:\ /g ; } " \ - '&& { gcloud compute disks list --filter="name:$N" 2>&1 | ' "sed --unbuffered s/^/Disks....:\ /g ; } " \ - '&& { gcloud compute instances list --filter="name:$N" 2>&1 | ' "sed --unbuffered s/^/Instances:\ /g ; } " \ - '&& { gcloud compute routers list --filter="name:$N" 2>&1 | ' "sed --unbuffered s/^/Routers..:\ /g ; } " \ - '&& { gcloud compute network-firewall-policies get-effective-firewalls --network="$N-network"' \ - " 2>&1 | sed --unbuffered s/^/Firewall:\ /g ; } " \ - - ) ;}" + [ $# -ge 3 ] && [[ -n "$(which-command tmux)" ]] \ + && printf "%s" "$3" > "/tmp/tmux-$1" \ + && _cmd=$( \ + printf "%s " \ + 'tmux resize-pane' \ + '-t "$TMUX_PANE"' \ + '-y $(cat "/tmp/tmux-' "$1" '") ; ' \ + ) \ + && eval $_cmd + _cmd="{ $(printf "%s " \ + "N='$N'; " \ + "${_cmd}" \ + "echo 'Listing $N stack:'; " \ + '{ gcloud compute networks' \ + 'list --filter="name:$N"' \ + '2>&1 | sed --unbuffered s/^/Networks.:\ /g ; } ' \ + '&& { gcloud compute networks subnets' \ + 'list --filter="name:$N"' ${GCP_SUBNETS_FORMAT} \ + '2>&1 | sed --unbuffered s/^/Subnets..:\ /g ; } ' \ + '&& { gcloud compute disks' ${GCP_DISKS_FORMAT} \ + 'list --filter="name:$N"' \ + '2>&1 | sed --unbuffered s/^/Disks....:\ /g ; } ' \ + '&& { gcloud compute instances' ${GCP_INSTANCES_FORMAT} \ + 'list --filter="name:$N"' \ + '2>&1 | sed --unbuffered s/^/Instances:\ /g ; } ' \ + '&& { gcloud compute routers' \ + 'list --filter="name:$N"' \ + '2>&1 | sed --unbuffered s/^/Routers..:\ /g ; } ' \ + '&& { gcloud compute network-firewall-policies' \ + 'get-effective-firewalls --network="$N-network"' \ + '2>&1 | sed --unbuffered s/^/Firewall:\ /g ; } ' \ + ) ;}" [ $# -ge 2 ] && _cmd="watch -n${2} '${_cmd}'" [[ -n ${SZ_DEBUG} ]] && printf "Executing: \n\t$_cmd\n\n" eval $_cmd } -# printf '\n\n'; gcp_get_stack 'dragonheart' 5 +# printf '\n\n'; gcp-get-stack 'dragonheart' 5 -function gcp_region() { +function gcp-region() { gcloud config get-value compute/region 2> /dev/null } diff --git a/_home/dot_sz.shrc.d/81_alacritty_colorscheme b/_home/dot_sz.shrc.d/81_alacritty_colorscheme new file mode 100644 index 0000000..a05022b --- /dev/null +++ b/_home/dot_sz.shrc.d/81_alacritty_colorscheme @@ -0,0 +1,6 @@ +[[ -n $(which-command alacritty-colorscheme) ]] \ + && alias alc="alacritty-colorscheme " \ + && alias alcls="alc list " \ + && alias alcset="alc apply " \ + && alias alcs="alc status " \ + && alias alct="alc toggle " diff --git a/_home/dot_sz.shrc.d/97_chezmoi_aliases b/_home/dot_sz.shrc.d/97_chezmoi_aliases index 67c9e9a..b045ada 100644 --- a/_home/dot_sz.shrc.d/97_chezmoi_aliases +++ b/_home/dot_sz.shrc.d/97_chezmoi_aliases @@ -1,3 +1,8 @@ +if [[ -z "$(which-command chezmoi)" && -x "$HOME/bin/chezmoi" ]]; then + function chezmoi() { + "$HOME/bin/chezmoi" "${@}" + } +fi if [[ -n "$(which-command chezmoi)" ]]; then export CHEZMOIROOT="$(chezmoi source-path)" export CZ="$CHEZMOIROOT" @@ -5,25 +10,65 @@ if [[ -n "$(which-command chezmoi)" ]]; then alias czcd="cd $CZ" alias czxcd="cd $CZ_X" + alias czx-edit="edit $CZ_X/.chezmoiexternal.*" function cz() { chezmoi "${@}"; } function czx() { chezmoi --source $CZ_X --config $HOME/.config/chezmoi.externals/config.toml "${@}" } - alias czs="cz status " - function czg() { - cz git -- "${@}" - } - #alias czg="cz git -- " - alias czgs="cz git -- status " + alias czs="cz status --exclude scripts " + + CZG_ROOT="$(cz git -- rev-parse --show-toplevel)" + alias czg="git --work-tree=$CZG_ROOT --git-dir=$CZG_ROOT/.git " + unset CZG_ROOT + + alias czgs="czg status " + alias czgca="czg add --all && czg commit " alias cza="cz apply && exec $SHELL" alias czu="cz upgrade && cz update && exec $SHELL " alias czxu="cz upgrade && cz update && czx apply && exec $SHELL " + alias czxa="czx apply && exec $SHELL " - alias cz-refresh="czs | cut -d\ -f2 | grep '^\.sz\.shrc\.d' | xargs cz forget --force; cz add ~/.sz.shrc.d --recursive; cz status; cz git status" + function cz-refresh() { + local _tmp + _tmp=$(chezmoi status --exclude scripts) + if [[ -n "$_tmp" ]]; then + echo "Adding modified files..." + cz re-add + else + echo "No modified files found." + fi + + _tmp=$(chezmoi unmanaged | grep "^${SFP/\./\\.}\.shrc\.d/" | while read u; do + printf "'$HOME/$u' " + done) + [[ -n "$(echo $_tmp | xargs)" ]] \ + && echo "Adding new files..." \ + && eval "chezmoi add --prompt $_tmp" + } + alias cz-commit="cz git -- commit -a " + function cz-get-data() { + chezmoi data --format json | jq -r ".${@:-${SFP#*.}}" + } + function cz-import-data() { + # Use this with eval: eval $(cz-import-data) + local tmp_SFP=${SFP^^} + tmp_SFP=${tmp_SFP#*.} + local UPPERCASE='|ascii_upcase' + local PREFIX="CZ_${tmp_SFP}_DATA_" + [[ "$1" == "promptString" ]] && unset UPPERCASE PREFIX + local RESULTS=$(cz-get-data | jq -r "to_entries[] | \"$PREFIX\(.key${UPPERCASE})=\\\"\(.value)\\\"\"") + if [[ "$1" == "promptString" ]] ; then + printf "$RESULTS" | tr '\n' ',' | sed 's/"//g; s/^\(.*\),$/"\1/g;' + #printf "$RESULTS" | tr '\n' ',' | sed 's/="/=/g; s/^\(.*\),$/"\1/g; s/,/,"/g;' + else + echo "$RESULTS" + fi + } + function cz-remove-missing() { pushd ~ > /dev/null changes=$(cz status | sed -n 's/^DA[ \t]\+//p') @@ -33,16 +78,6 @@ if [[ -n "$(which-command chezmoi)" ]]; then popd > /dev/null } - function cz-add-changes() { - pushd ~ > /dev/null - changes=$(cz status | sed -n 's/^MM[ \t]\+//p') - for c in $changes; do - echo Adding $c - cz add $c - done - popd > /dev/null - } - function cz-set-ssh-github() { cz git -- remote set-url origin "$( \ cz git -- remote get-url origin \ diff --git a/_home/dot_sz.shrc.d/bash.post/10_oh-my-posh.hook b/_home/dot_sz.shrc.d/bash.post/10_oh-my-posh.hook index cb1d1d6..a598361 100644 --- a/_home/dot_sz.shrc.d/bash.post/10_oh-my-posh.hook +++ b/_home/dot_sz.shrc.d/bash.post/10_oh-my-posh.hook @@ -1,6 +1,6 @@ if [[ -n "$(which-command oh-my-posh)" ]]; then OHMYPOSH_CONFIG='' - [[ -r ~/.poshtheme.omp.json ]] && OHMYPOSH_CONFIG="--config ~/.poshtheme.omp.json" - eval "$(oh-my-posh init bash $OHMYPOSH_CONFIG)" + [[ -r ~/.poshtheme.omp.json ]] && OHMYPOSH_CONFIG="~/.poshtheme.omp.json" + eval "$(oh-my-posh init bash --config $OHMYPOSH_CONFIG)" unset OHMYPOSH_CONFIG fi diff --git a/_home/dot_sz.shrc.d/bash.post/99_alacritty-colorscheme.completion b/_home/dot_sz.shrc.d/bash.post/99_alacritty-colorscheme.completion new file mode 100644 index 0000000..0a143e7 --- /dev/null +++ b/_home/dot_sz.shrc.d/bash.post/99_alacritty-colorscheme.completion @@ -0,0 +1,2 @@ +[[ -n "$BASH_COMPLETION_EXIST" && -n $(which-command alacritty-colorscheme) ]] \ + && complete -W "$(alacritty-colorscheme list)" alacritty-colorscheme alc alcset alct diff --git a/_home/dot_sz.shrc.d/bash.post/99_chezmoi.completion b/_home/dot_sz.shrc.d/bash.post/99_chezmoi.completion index 1d5b966..7456b67 100644 --- a/_home/dot_sz.shrc.d/bash.post/99_chezmoi.completion +++ b/_home/dot_sz.shrc.d/bash.post/99_chezmoi.completion @@ -4,10 +4,6 @@ | add-alias-to-bash-completion-code chezmoi cz czx \ | add-alias-to-bash-completion-code chezmoi czx \ ) \ - echo done. -# && if [[ $(type -t compopt) = "builtin" ]]; then -# complete -o default -F __git_complete czg -# else -# complete -o default -o nospace -F __git_complete czg -# fi - + && complete -F _complete_alias czs \ + && complete -F _complete_alias czg \ + && complete -F _complete_alias czgs diff --git a/_home/dot_sz.shrc.d/bash.pre/10_check_completion b/_home/dot_sz.shrc.d/bash.pre/10_check_completion index 4b4fe8c..8517dae 100644 --- a/_home/dot_sz.shrc.d/bash.pre/10_check_completion +++ b/_home/dot_sz.shrc.d/bash.pre/10_check_completion @@ -1,5 +1,8 @@ if [[ -r /usr/share/bash-completion/bash_completion ]]; then - BASH_COMPLETION_EXIST=1 - shopt -s direxpand + BASH_COMPLETION_EXIST=1 + shopt -s direxpand + + [[ -r ~/.local/share/complete-alias/complete_alias ]] \ + && source ~/.local/share/complete-alias/complete_alias fi diff --git a/_home/dot_sz.shrc.d/bash.pre/21_aliases b/_home/dot_sz.shrc.d/bash.pre/21_aliases index 0fda67a..45c7ebb 100644 --- a/_home/dot_sz.shrc.d/bash.pre/21_aliases +++ b/_home/dot_sz.shrc.d/bash.pre/21_aliases @@ -1,5 +1,9 @@ -alias which-command="type -fP " function which-command() { + local ANSWER=$(type -t "${@}") || return $? + [[ $ANSWER == "function" ]] && printf "function " && type "${@}" | tail +2 && return + [[ $ANSWER == "alias" ]] && { + alias "${@}" + } type -fP "${@}" } diff --git a/_home/dot_sz.shrc.d/zsh.pre/21_aliases b/_home/dot_sz.shrc.d/zsh.pre/21_aliases index b8859c6..6322c4d 100644 --- a/_home/dot_sz.shrc.d/zsh.pre/21_aliases +++ b/_home/dot_sz.shrc.d/zsh.pre/21_aliases @@ -1 +1,9 @@ -alias which-command="whence " +function which-command() { + local ANSWER=$(whence -w "${@}") || return $? + ANSWER=${ANSWER##*: } + [[ $ANSWER == "function" ]] && printf "function " && whence -f "${@}" && return + [[ $ANSWER == "alias" ]] && { + alias "${@}" + } + whence "${@}" +} diff --git a/_home/private_dot_local/bin/executable_get-github-release.sh b/_home/private_dot_local/bin/executable_get-github-release.sh new file mode 100644 index 0000000..dd16b97 --- /dev/null +++ b/_home/private_dot_local/bin/executable_get-github-release.sh @@ -0,0 +1,20 @@ +#! /usr/bin/env bash + +GH_PROJECT="${1}" +GH_DL_TAG="${2:-latest}" +GH_FILTER="${3:-deb}" +if [[ ! "$GH_FILTER" =~ '(' ]]; then + GH_FILTER="contains(\"${GH_FILTER}\")" +fi +SRC_URL=https://api.github.com/repos/${GH_PROJECT}/releases/${GH_DL_TAG} +DL_URL=$( \ + curl -sL curl ${SRC_URL} \ + | jq -r " \ + .assets[] \ + | select(.browser_download_url \ + | ${GH_FILTER} ) \ + | .browser_download_url \ + ") +[[ -n "$DL_URL" ]] \ + && printf "%s\n" $DL_URL \ + || return 1 2>/dev/null || exit 1 diff --git a/_home/private_dot_local/bin/executable_identify-large-git-blobs b/_home/private_dot_local/bin/executable_identify-large-git-blobs new file mode 100644 index 0000000..5ecbca1 --- /dev/null +++ b/_home/private_dot_local/bin/executable_identify-large-git-blobs @@ -0,0 +1,13 @@ +#! /usr/bin/env bash + +LIMIT=${1:-10} +REV_LIST="$(git rev-list --objects --all)" +find $(git rev-parse --git-dir)/objects/pack -type f -name "pack-*.idx" \ +| while read pack; do + git verify-pack -v "$pack" | sort -nrk 3 | head -${LIMIT} +done | sort -nrk 3 | head -${LIMIT} \ +| while read blobinfo; do + blob=$(echo "$blobinfo" | cut -f1 -d' ') + printf "%s %12s %s\n" $(echo "$blobinfo" | cut -f1,5 -d' ') "$(echo "$REV_LIST" | grep "$blob" | cut -f2 -d' ';)" +done +unset REV_LIST diff --git a/_home/private_dot_local/bin/executable_install-deb-from-web.sh b/_home/private_dot_local/bin/executable_install-deb-from-web.sh new file mode 100644 index 0000000..b00228d --- /dev/null +++ b/_home/private_dot_local/bin/executable_install-deb-from-web.sh @@ -0,0 +1,15 @@ +#! /usr/bin/env bash + +DL_URL="${1}" +DL_FILENAME="${2:-${DL_URL##*/}}" +DL_DIR=$(mktemp -dt) +cd "$DL_DIR" +# Download the .deb file +wget "$DL_URL" +# Install the package +sudo dpkg -i "${DL_FILENAME}" +# Clean up +rm "${DL_FILENAME}" +cd / +rmdir "$DL_DIR" + diff --git a/_home/private_dot_local/bin/executable_launch-teamviewer-quicksupport.sh b/_home/private_dot_local/bin/executable_launch-teamviewer-quicksupport.sh deleted file mode 100644 index 16ff380..0000000 --- a/_home/private_dot_local/bin/executable_launch-teamviewer-quicksupport.sh +++ /dev/null @@ -1,53 +0,0 @@ -#! /usr/bin/env bash - -set -e - -### based on the code shared at https://community.teamviewer.com/English/discussion/comment/116988/#Comment_116988 - -clear -cat </dev/null | awk '{ print $1 }')" - -if [[ ! -r "${LocalFile}" ]] || [ "$LocalSize" != "$RemoteSize" ]; then - echo "Downloading file into $LocalFile..." - curl -Lo "$LocalFile" "$RemoteFile" -else - echo "$LocalFile exists and is same size as on server, using existing file..." -fi - -rm -fR /tmp/tvqs 2>&1 > /dev/null -mkdir -p /tmp/tvqs -pushd /tmp/tvqs > /dev/null -tar xzf "$LocalFile" -cd teamviewerqs -echo "Launching TeamViewer Quick Support in the background from $PWD, it should startup in a few seconds..." -./teamviewer & -sleep 8 -popd -printf "TeamViewer launched, you might want to hit if you don't see the prompt\n\n" diff --git a/_home/private_dot_local/bin/executable_sz-doctor b/_home/private_dot_local/bin/executable_sz-doctor index bb9d7c8..0f54213 100644 --- a/_home/private_dot_local/bin/executable_sz-doctor +++ b/_home/private_dot_local/bin/executable_sz-doctor @@ -1,4 +1,5 @@ #! /usr/bin/env bash +SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) USER_HOME=$HOME [[ -n "${SUDO_USER}" ]] && USER_HOME="$(eval "echo ~${SUDO_USER}")" . ${SHRC_D:-$USER_HOME/.pqb.shrc.d}/01_util.functions diff --git a/_home/private_dot_local/bin/executable_sz-help b/_home/private_dot_local/bin/executable_sz-help new file mode 100644 index 0000000..787beca --- /dev/null +++ b/_home/private_dot_local/bin/executable_sz-help @@ -0,0 +1,84 @@ +#! /usr/bin/env bash + +SHOW_ALIASES=0 +SHOW_FUNCTIONS=0 +SHOW_MEMBASED=0 +SHOW_SCRIPTS=0 + +NAME="${0##*/}" +eval set -- $(getopt --name "$NAME" --options 'afmsh' --longoptions aliases,functions,membased,scripts,all,help -- "${@}") + +ARG_COUNT=0 +SHOW_USAGE=0 +while [[ $# -gt 0 ]] +do + opt="$1"; + #expose next argument + shift; + case "$opt" in + '--' ) break 2;; + '-h'|'-?' ) + opt='--help' ;; + '-a' ) + opt='--aliases' ;; + '-f' ) + opt='--functions' ;; + '-m' ) + opt='--membased' ;; + '-s' ) + opt='--scripts' ;; + esac + ((ARG_COUNT++)) + case "$opt" in + '--help' ) SHOW_USAGE=1; break 2;; + '--aliases' ) + SHOW_ALIASES=1 ;; + '--functions' ) + SHOW_FUNCTIONS=1 ;; + '--membased' ) + SHOW_MEMBASED=1 ;; + '--scripts' ) + SHOW_SCRIPTS=1 ;; + *) echo >&2 "Invalid option: $@"; exit 1;; + esac +done + +# If no args, show_usage +[[ $ARG_COUNT -eq 0 ]] && SHOW_SCRIPTS=0 + +if [[ "$SHOW_USAGE" == "1" ]]; then + printf "%s\n" \ + "${0##*/}: ${0##*/} [-afhms] [--aliases] [--functions] [--help] [--membased] [--script]" \ + " List POLARISqb productivity and helpdesk commands supplied by ITOps" \ + "" \ + " Options:" \ + " -a | --aliases List aliases defined in Pqb startup scripts" \ + " -f | --functions List functions defined in Pqb startup scripts" \ + " -h | --help Display this usage message" \ + " -m | --membased List all memory based commands (aka, aliases " \ + " and functions)." \ + " -s | --scripts List Pqb supplied utility scripts" \ + " This is the default when no arguments are passed" \ + "" + + return 2>/dev/null || exit +fi +FILTER="" +if [[ "$SHOW_ALIASES" == "1" || "$SHOW_MEMBASED" == "1" ]]; then + FILTER+="^\W*alias\|" +fi +if [[ "$SHOW_FUNCTIONS" == "1" || "$SHOW_MEMBASED" == "1" ]]; then + FILTER+="^\W*functions\|" +fi +if [[ -n "$FILTER" ]]; then + FILTER=${FILTER%\\|*} + find ~/.pqb.shrc.d -type f \ + | xargs grep "${FILTER}" \ + | sed 's/^.*\.d\///; s/:.*function /:(f) /; s/() {.*$//; s/:.*alias /:(a) /; s/=.*$//;' +fi + +[[ "$SHOW_ALIASES" == "0" && "$SHOW_MEMBASED" == "0" && "$SHOW_MEMBASED" == "0" ]] && SHOW_SCRIPTS=1 + +if [[ "$SHOW_SCRIPTS" == "1" ]]; then + find ~/.local/bin -executable -type f -name "pqb*" -printf "%f\n" +fi diff --git a/_home/private_dot_local/bin/executable_sz-setup-user-env b/_home/private_dot_local/bin/executable_sz-setup-user-env new file mode 100644 index 0000000..d725773 --- /dev/null +++ b/_home/private_dot_local/bin/executable_sz-setup-user-env @@ -0,0 +1,70 @@ +#! /usr/bin/env bash +SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) +USER_HOME=$HOME +[[ -n "${SUDO_USER}" ]] && USER_HOME="$(eval "echo ~${SUDO_USER}")" + +source $(ls -1 ~/.*.shrc | head -1); [[ -z "${SHRC_D}" ]] && { echo "ERROR: Couldn't load ~/.*.shrc script!" 1>&2; return 1 2>/dev/null; exit 1; } +source ${SHRC_D}/${SHELL##*/}.pre/21_aliases +source ${SHRC_D}/01_util.functions +source ${SHRC_D}/97_chezmoi_aliases + +set -e + +require_sudo \ + || eval $(error 3 "POLARISqb: Not in sudo group, skipping $(basename $0)") + +printf "%s\n" \ + "POLARISqb Workstation/Laptop Owner initialization tool" \ + "" \ + "The machine will be initialized with the following values unless" \ + "specified otherwise:" \ + "" \ + $(cz-import-data) \ + "" + +eval "$(cz-import-data)" + +if [[ -z "${CZ_PQB_DATA_LOCAL_USER_NAME}" ]]; then eval $(error 1 \ + "local_user_name not defined in 'cehzmoi data', " "please run 'chezmoi init' or 'chezmoi edit-config' to fix, then try again" +); fi + +if [[ -n "$(getent passwd ${CZ_PQB_DATA_LOCAL_USER_NAME})" ]]; then eval $(error 2 \ + "User '${CZ_PQB_DATA_LOCAL_USER_NAME}' already exists, aborting." +); fi + +#gecos field: "Full_Name,Room_Number,Work_Phone,Home_Phone,Other" +sudo adduser --disabled-password --gecos "${CZ_PQB_DATA_LOCAL_OWNER_NAME},,,,${CZ_PQB_DATA_EMAIL}" ${CZ_PQB_DATA_LOCAL_USER_NAME} +sudo adduser ${CZ_PQB_DATA_LOCAL_USER_NAME} sudo +INITIAL_PASSWORD='password' +printf "${CZ_PQB_DATA_LOCAL_USER_NAME}:${INITIAL_PASSWORD}" | sudo chpasswd + +NEW_USER_HOME=$( eval "printf ~${CZ_PQB_DATA_LOCAL_USER_NAME}" ) +if [[ -z "${NEW_USER_HOME}" ]]; then eval $(error 3 \ + "Something is wrong, couldn't find the home dir for ${CZ_PQB_DATA_LOCAL_USER_NAME}!" +); fi + +NEW_HOSTNAME="${CZ_PQB_DATA_LOCAL_USER_NAME}-pqb" +[[ "$(hostname)" != "${NEW_HOSTNAME}" ]] && sudo hostname $NEW_HOSTNAME + +_CZ_REMOTE_URL=$(chezmoi git -- remote get-url origin) +_CZ_REMOTE_BRANCH=$(chezmoi git -- branch --show-current) +_CZ_DATA_PAIRS="$(cz-import-data promptString)" +cat ~/.config/chezmoi/chezmoi.toml | env sudo -u ${CZ_PQB_DATA_LOCAL_USER_NAME} -- sh -c "mkdir -p ~/.config/chezmoi; cat - > ~/.config/chezmoi/chezmoi.toml" +sudo -u ${CZ_PQB_DATA_LOCAL_USER_NAME} -- sh -c "cd ~; $(curl -fsLS chezmoi.io/get)" -- init --promptString="${_CZ_DATA_PAIRS}" --apply --branch "${_CZ_REMOTE_BRANCH}" "${_CZ_REMOTE_URL}" + +echo "Chezmoi complete" + +CUR_USER=$SUDO_USER +[[ -z "$CUR_USER" ]] && CUR_USER=$USER + +# setup local git config values +git config --global --get user.email > /dev/null || git config --global user.email "${CUR_USER}@${NEW_HOSTNAME}" +git config --global --get user.name > /dev/null || git config --global user.name $(getent passwd $USER | cut -d':' -f5 | cut -d',' -f1) + +sudo -u ${CZ_PQB_DATA_LOCAL_USER_NAME} -- sh -c "cd ~; git config --global user.email '${CZ_PQB_DATA_EMAIL}' && git config --global user.name '${CZ_PQB_DATA_LOCAL_OWNER_NAME}'" + +sudo chage -d0 ${CZ_PQB_DATA_LOCAL_USER_NAME} + +#${CZ_PQB_DATA_EMAIL} +#${CZ_PQB_DATA_LOCAL_OWNER_NAME} +#${CZ_PQB_DATA_LOCAL_USER_NAME}