Push improvements form the PQB work

This commit is contained in:
Gal Szkolnik 2022-09-29 18:29:13 -04:00
parent f3323b159b
commit 1e3c60630e
68 changed files with 409 additions and 219 deletions

View file

@ -1,3 +1,7 @@
warn() {
(>&2 printf '\E[34mWARNING:\E[0m %s\n' "$@" )
}
error() {
(>&2 printf '\E[31mERROR:\E[0m %s\n' "$@" )
}
@ -9,6 +13,13 @@ require_root() {
fi
}
recommend_root() {
if [[ $EUID -ne 0 ]]; then
warn "This script works better using sudo or as the root user"
return 3
fi
}
function setacl() {
if [[ $# -lt 4 ]]; then
error "setacl missing arguments, called with '$1' ${@:2}"

View file

@ -1,5 +1,3 @@
alias sudo="/usr/bin/sudo "
# some more ls aliases
alias ll='ls -alF'
alias la='ls -A'
@ -7,12 +5,10 @@ alias l='ls -CF'
alias lessr="less --raw-control-chars "
alias sz-edshrc="ed ~/.sz.shrc.d ; exec $SHELL"
alias edshrc="ed ~/${SFP}.shrc.d && exec $SHELL"
[[ -z "$(env inkscape 2> /dev/null)" && -n "$(flatpak info org.inkscape.Inkscape 2> /dev/null)" ]] && alias inkscape="flatpak run org.inkscape.Inkscape "
alias cdgit='cd $(git rev-parse --show-toplevel) '
function clip() {
xclip -i -sel clipboard
}

View file

@ -1,17 +1,6 @@
PREFERED_VI=$(which-command nvim vim | head -1)
if [[ -z "$PREFERED_VI" ]]; then
PREFERED_VI=$(which-command vi | head -1)
MY_VI="$(type -fP my_vi)"
if [[ -z "$PREFERED_VI" ]]; then
alias my_vi='eval $EDITOR '
else
alias my_vi="$PREFERED_VI"
fi
else
alias my_vi="$PREFERED_VI -p"
fi
export DOOMROOT="$HOME/.config/_my.emacs/doom"
port DOOMROOT="$HOME/.config/_my.emacs/doom"
[[ -x $DOOMROOT/emacs.d/bin/doom ]] && function doom() {
export EMACSDIR="$DOOMROOT/emacs.d"
export DOOMDIR="$DOOMROOT/config"
@ -23,17 +12,18 @@ export DOOMROOT="$HOME/.config/_my.emacs/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'
&& -n "$(which-command emacsclient)" \
&& -n "$(which-command emacs)" \
&& -n "$(which-command edit-with-spacemacs)" \
]]; then
alias my_editor='edit-with-spacemacs'
else
alias my_editor='my_vi'
alias my_editor="${MY_VI} "
fi
alias nvim="my_vi"
alias vim="my_vi"
alias vi="my_vi"
alias nvim="${MY_VI} "
alias vim="${MY_VI} "
alias vi="${MY_VI} "
alias ed="my_editor"
alias edit="my_editor"

View file

@ -0,0 +1,8 @@
#alias sudo="/usr/bin/sudo "
function sudo() {
local cli="$(command -v "${1}")"
[[ -x "$cli" ]] || cli="${1}"
/usr/bin/sudo --preserve-env=PATH -- "$cli" "${@:2}"
}

View file

@ -0,0 +1,7 @@
if [[ -n "$(which-command git)" ]]; then
alias gitcd='cd $(git rev-parse --show-toplevel) '
if [[ -n $(git credential-manager-core --version 2>/dev/null) ]]; then
export GCM_CREDENTIAL_STORE=plaintext
fi
fi

View file

@ -1,48 +1,61 @@
if [[ -n "$(which-command chezmoi)" ]]; then
export CHEZMOIROOT="$(chezmoi source-path)"
export CZ="$CHEZMOIROOT"
export CZ_X="$(readlink -f $CHEZMOIROOT/../_externals)"
export CHEZMOIROOT="$(chezmoi source-path)"
export CZ="$CHEZMOIROOT"
export CZ_X="$(readlink -f $CHEZMOIROOT/../_externals)"
alias czcd="cd $CZ"
alias czxcd="cd $CZ_X"
alias cz="chezmoi "
alias czx="chezmoi --source $CZ_X --config $HOME/.config/chezmoi/chezmoi.externals.toml "
alias czcd="cd $CZ"
alias czxcd="cd $CZ_X"
function cz() { chezmoi "${@}"; }
function czx() {
chezmoi --source $CZ_X --config $HOME/.config/chezmoi.externals/config.toml "${@}"
}
alias czs="cz status "
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"
alias cz-commit="cz git -- commit -a "
alias czs="cz status "
function czg() {
cz git -- "${@}"
}
#alias czg="cz git -- "
alias czgs="cz git -- status "
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 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"
alias cz-commit="cz git -- commit -a "
function cz() {
chezmoi "${@}"
}
function cz-remove-missing() {
pushd ~ > /dev/null
changes=$(cz status | sed -n 's/^DA[ \t]\+//p')
for c in $changes; do
cz rm $c
done
popd > /dev/null
}
function cz-remove-missing() {
pushd ~ > /dev/null
changes=$(cz status | sed -n 's/^DA[ \t]\+//p')
for c in $changes; do
cz rm $c
done
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-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 | sed 's|https://github.com/|git@github.com:|')"
cz git -- remote get-url origin
}
function cz-set-ssh-github() {
cz git -- remote set-url origin "$( \
cz git -- remote get-url origin \
| sed 's|https://github.com/|git@github.com:|' \
)"
cz git -- remote get-url origin
}
function cz-set-https-github() {
cz git -- remote set-url origin "$(cz git -- remote get-url origin | sed 's|git@github.com:|https://github.com/|')"
cz git -- remote get-url origin
}
function cz-set-https-github() {
cz git -- remote set-url origin "$( \
cz git -- remote get-url origin \
| sed 's|git@github.com:|https://github.com/|' \
)"
cz git -- remote get-url origin
}
fi

View file

@ -1,5 +0,0 @@
if [[ -n "$(type -fP chezmoi)" ]]; then
CHEZMOI_OUT="$(chezmoi status || true)x"
[[ "x" != "$CHEZMOI_OUT" ]] && printf "\nChezmoi changes:\n" && echo "${CHEZMOI_OUT%?}"
unset CHEZMOI_OUT
fi

View file

@ -4,4 +4,11 @@ export HISTFILESIZE=100000 # big big history
shopt -s histappend # append to history, don't overwrite it
# Save and reload the history after each command finishes
export PROMPT_COMMAND="history -a; history -c; history -r; $PROMPT_COMMAND"
function _history_hook() {
history -a; history -c; history -r
}
export PROMPT_COMMAND="$( \
echo "$PROMPT_COMMAND" \
| sed 's/;\ *$//; s/; _history_hook//g' \
); _history_hook"

View file

@ -1,4 +1,4 @@
if [[ -n "$(type -fP direnv)" ]]; then
source <( direnv hook bash )
source <( direnv stdlib )
source <( direnv hook bash )
source <( direnv stdlib )
fi

View file

@ -0,0 +1,2 @@
# BC_PATH=$(which-command bash-complete-alias)
# [[ -n "$BC_PATH" && -r "$BC_PATH" ]] && source "$BC_PATH"

View file

@ -1 +0,0 @@
[[ -n "$BASH_COMPLETION_EXIST" && -n $(which-command chezmoi) ]] && source <(chezmoi completion bash | add-alias-to-bash-completion-code chezmoi cz )

View file

@ -0,0 +1,13 @@
[[ -n "$BASH_COMPLETION_EXIST" && -n $(which-command chezmoi) ]] \
&& source <( \
chezmoi completion bash \
| 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

View file

@ -1 +0,0 @@
[[ -n "$(which-command oh-my-posh)" ]] && source <(oh-my-posh completion bash)

View file

@ -0,0 +1,2 @@
[[ -n "$(which-command oh-my-posh)" ]] \
&& source <( oh-my-posh completion bash )

View file

@ -1,21 +0,0 @@
if ( uname --kernel-release | grep -q truenas ); then
# Completion code is only avialable with `sudo`, the aliases below
# are desined for 'lazy-loading' the completion code, when it's time
# to enter the sudo password.
if [[ -n "$(which-command 'k3s')" ]]; then
alias kubectl=' \
### Lazy load `kubectl` bash-completion \
alias kubectl="sudo k3s kubectl "; \
source <( kubectl completion bash ); \
sudo k3s kubectl '
fi
if [[ -n "$(which-command 'helm')" ]]; then
alias helm=' \
### Lazy load `helm` bash-completion \
alias helm="sudo KUBECONFIG=/etc/rancher/k3s/k3s.yaml helm "; \
source <( helm completion bash ); \
sudo KUBECONFIG=/etc/rancher/k3s/k3s.yaml helm '
fi
fi