config/shell: function adjustments

This commit is contained in:
xeruf 2024-09-03 15:10:43 +03:00
parent e888d12fb9
commit 886b3b9172
4 changed files with 62 additions and 19 deletions

View File

@ -45,7 +45,7 @@ yas() {
) )
if test -n "$pkg" if test -n "$pkg"
then echo "Installing $pkg..." then echo "Installing $pkg..."
cmd="yay -Sy --batchinstall --rebuildtree $pkg" cmd="yay -Sy --batchinstall --rebuildall $pkg"
print -s "$cmd" print -s "$cmd"
eval "$cmd" eval "$cmd"
rehash rehash

View File

@ -289,12 +289,12 @@ u() {
fi fi
if command -v topgrade >/dev/null if command -v topgrade >/dev/null
then then
nice -10 topgrade --disable node emacs remotes nice -10 topgrade --disable node emacs remotes rustup nix
if test -d "$XDG_CONFIG_HOME/emacs" if test -d "$XDG_CONFIG_HOME/emacs"
then then
builtin cd $XDG_CONFIG_HOME/emacs builtin cd $XDG_CONFIG_HOME/emacs
git pull --rebase git pull --rebase
if ! true | doom sync -u if ! true | doom --force upgrade
then echo "Rebuild doom from scratch?" then echo "Rebuild doom from scratch?"
read result read result
test "$result" = "y" && rm -rf "$DOOMLOCALDIR/straight" && doom sync -u test "$result" = "y" && rm -rf "$DOOMLOCALDIR/straight" && doom sync -u
@ -342,8 +342,9 @@ sshl() {
! [[ "$1" =~ "nc-*" ]] && ! [[ "$1" =~ "nc-*" ]] &&
! [[ "$1" =~ "ddns*" ]] && ! [[ "$1" =~ "ddns*" ]] &&
local pass=pass local pass=pass
local target=${1%[0-9a-z]}
test "$all" && test "$all" &&
find $XDG_CONFIG_HOME/bash/ \( -name aliases.bash -o -name "${1%[0-9a-z]}*.bash" \) -exec cat {} + | $pass ssh "$@" 'cat > .bash_aliases && grep -q .bash_aliases .bashrc || echo "source ~/.bash_aliases" | tee -a .bashrc' && find $XDG_CONFIG_HOME/bash/ \( -name aliases.bash -o -name "${target#nc-}*.bash" \) -exec cat {} + | $pass ssh "$@" 'cat > .bash_aliases && grep -q .bash_aliases .bashrc || echo "source ~/.bash_aliases" | tee -a .bashrc' &&
echo 'Updated .bash_aliases!' echo 'Updated .bash_aliases!'
#$pass ssh "$1" 'grep -q ".bash_aliases" .bashrc || echo "source ~/.bash_aliases" >>.bashrc' #$pass ssh "$1" 'grep -q ".bash_aliases" .bashrc || echo "source ~/.bash_aliases" >>.bashrc'
if test -n "$pass" if test -n "$pass"
@ -507,8 +508,11 @@ which exa >/dev/null &&
alias ll='l --long --git --all' alias ll='l --long --git --all'
if which fd >/dev/null 2>&1 if which fd >/dev/null 2>&1
then fn() { $(command -v fd || echo fdfind) --hidden --no-ignore-vcs --one-file-system "$@" | less -F; } # [F]ind [n]o ignore then
alias ff="noglob fn --color=always " # [F]ind [F]ile # [F]ind [n]o ignore
fn() { $(command -v fd || echo fdfind) --hidden --no-ignore-vcs --one-file-system "$@" | less -F; }
# [F]ind [F]ile
alias ff="noglob fn --color=always "
compdef ff=fd compdef ff=fd
compdef fn=fd compdef fn=fd
else else

View File

@ -31,10 +31,10 @@ mozedit() (
cat "$tmpfile2" | sed "$2" | lz4 -l | dd bs=1 skip=8 seek=12 of="$file" conv=notrunc cat "$tmpfile2" | sed "$2" | lz4 -l | dd bs=1 skip=8 seek=12 of="$file" conv=notrunc
) )
test "$XDG_CURRENT_DESKTOP" = "KDE" || return 0 # Switch theme across system: KDE, Konsole, taskwarrior, bat, diffr (git pager)
# WIP: Emacs, Mozilla
# Switch theme across system: KDE, Konsole, taskwarrior, bat # TODO terminal tool themer https://www.linuxjournal.com/content/revolutionizing-command-line-interface-dynamic-themes
# WIP: Emacs, Mozilla, diffr (git pager) # TODO bluetuith
theme_save="$XDG_CACHE_HOME/theme" theme_save="$XDG_CACHE_HOME/theme"
#theme_default="$(d=$(date +%H) && test $d -gt 7 && test $d -lt 19 && echo light || echo dark)" #theme_default="$(d=$(date +%H) && test $d -gt 7 && test $d -lt 19 && echo light || echo dark)"
theme_default="dark" theme_default="dark"
@ -44,35 +44,47 @@ themeswitch() {
then kcmshell5 kcm_lookandfeel then kcmshell5 kcm_lookandfeel
elif test "$theme" != "$THEME" -a "$2" != "q" elif test "$theme" != "$THEME" -a "$2" != "q"
then kcmshell5 kcm_lookandfeel & then kcmshell5 kcm_lookandfeel &
# TODO theme diffr rather than disabling it
bak $XDG_CONFIG_HOME/git/diffr
emacsclient -e "(toggle-theme \"$theme\")" emacsclient -e "(toggle-theme \"$theme\")"
fi fi
# TODO kitty
export THEME="$theme" export THEME="$theme"
echo "$theme">"$theme_save" echo "$theme">"$theme_save"
diffr="$XDG_CONFIG_HOME/git/diffr"
ln -srf "$diffr-$theme" "$diffr"
#mozfile=$(find $HOME/.mozilla/firefox/ -maxdepth 2 -name addonStartup.json.lz4 | grep ".test") #mozfile=$(find $HOME/.mozilla/firefox/ -maxdepth 2 -name addonStartup.json.lz4 | grep ".test")
kitty="$XDG_CONFIG_HOME/kitty/theme.conf"
case "$theme" in case "$theme" in
(light) (light)
alias ai='aichat --light-theme'
# LESS_TERMCAP_DEBUG=true man man # LESS_TERMCAP_DEBUG=true man man
export LESS_TERMCAP_md=$'\e[1;34m' # bold blue export LESS_TERMCAP_md=$'\e[1;34m' # bold blue
export BAT_THEME="OneHalfLight" export BAT_THEME="OneHalfLight"
konsoleprofile colors="Light" #konsoleprofile colors="Light"
ln -srf "$(dirname "$kitty")/theme-light.conf" "$kitty"
#sed -i 's/#\(include.*\/light-256.theme\)/\1/' "$XDG_CONFIG_HOME/task/taskrc" #sed -i 's/#\(include.*\/light-256.theme\)/\1/' "$XDG_CONFIG_HOME/task/taskrc"
#mozedit $mozfile '/light@mozilla/,/"enabled"/ s/\("enabled":.*\)false/\1true/; /dark@mozilla/,/"enabled"/ s/\("enabled":.*\)true/\1false/' #mozedit $mozfile '/light@mozilla/,/"enabled"/ s/\("enabled":.*\)false/\1true/; /dark@mozilla/,/"enabled"/ s/\("enabled":.*\)true/\1false/'
;; ;;
(dark) (dark)
alias ai=aichat
export BAT_THEME="OneHalfDark" export BAT_THEME="OneHalfDark"
konsoleprofile colors="Breeze" #konsoleprofile colors="Breeze"
rm -f "$kitty"
#sed -i 's/^include.*light-256.theme/#\0/' "$XDG_CONFIG_HOME/task/taskrc" #sed -i 's/^include.*light-256.theme/#\0/' "$XDG_CONFIG_HOME/task/taskrc"
#mozedit $mozfile '/light@mozilla/,/"enabled"/ s/\("enabled":.*\)true/\1false/; /dark@mozilla/,/"enabled"/ s/\("enabled":.*\)false/\1true/' #mozedit $mozfile '/light@mozilla/,/"enabled"/ s/\("enabled":.*\)true/\1false/; /dark@mozilla/,/"enabled"/ s/\("enabled":.*\)false/\1true/'
;; ;;
esac esac
pkill --signal SIGUSR1 kitty
} }
export THEME=$(cat "$theme_save" 2> /dev/null) export THEME=$(cat "$theme_save" 2> /dev/null)
export THEME=${THEME:-$theme_default} export THEME=${THEME:-$theme_default}
themeswitch $THEME themeswitch $THEME
alias ts='themeswitch'
alias ky='ai --role swahili'
alias en='ai --role en'
test "$XDG_CURRENT_DESKTOP" = "KDE" || return 0
# Fix errors regarding broken mim database # Fix errors regarding broken mim database
alias fixmime='sudo rm /usr/share/mime/packages/kde.xml && sudo update-mime-database /usr/share/mime' alias fixmime='sudo rm /usr/share/mime/packages/kde.xml && sudo update-mime-database /usr/share/mime'

View File

@ -45,7 +45,24 @@ stack() {
#test "$PWD" = "$HOME" && builtin cd "$STACKSPIN" #test "$PWD" = "$HOME" && builtin cd "$STACKSPIN"
;; ;;
(activate) (activate)
test -d "$STACKSPIN" && . $STACKSPIN/env/bin/activate test -d "$STACKSPIN" && . "$STACKSPIN/env/bin/activate"
;;
(setup) # https://docs.stackspin.net/en/latest/installation/install_cli.html
cd "$STACKSPIN" &&
python3 -m venv env &&
"$0" activate
;;
(override)
cd "$STACKSPIN/../stackspout/overrides"
name=stackspin-$1-override
echo "apiVersion: v1
kind: ConfigMap
metadata:
namespace: stackspin-apps
name: $name
data:
values.yaml: |" >"$name.yaml"
$EDITOR "$name.yaml"
;; ;;
(sso) "$cmdname" exec dashboard-backend -- flask "$@";; (sso) "$cmdname" exec dashboard-backend -- flask "$@";;
(users) (users)
@ -130,9 +147,13 @@ stack() {
) )
;; ;;
(backup) (backup)
if test $# -gt 0
then velero "$@"
else
backupname=$(date +%y%m%d.%H%m) backupname=$(date +%y%m%d.%H%m)
velero create backup $backupname --exclude-namespaces velero --wait velero create backup $backupname --exclude-namespaces velero --wait
velero backup logs $backupname;; velero backup logs $backupname
fi;;
(restore) (restore)
if test $# -lt 2 if test $# -lt 2
then echo "$0 $command <backup> <app> [namespace]" then echo "$0 $command <backup> <app> [namespace]"
@ -189,7 +210,7 @@ stack() {
# KUBE # KUBE
# app clis # app clis
(occ) "$cmdname" exec nc-nextcloud -c nextcloud -it -- su www-data -s /bin/bash -c "php $command $*";; (occ) "$cmdname" exec nc-nextcloud -c nextcloud -it -- su www-data -s /bin/bash -c "php $command $*";;
(zulip) "$cmdname" exec zulip -- su zulip -c "/home/zulip/deployments/current/manage.py $*";; (zulip) "$cmdname" exec zulip -- su zulip -c "/home/zulip/deployments/current/scripts/$* || /home/zulip/deployments/current/manage.py $*";;
(vikunja*) (vikunja*)
local pod=$command local pod=$command
case "$1" in case "$1" in
@ -271,7 +292,8 @@ stack() {
kubectl cp "$2" -n $("$cmdname" pod "$1$pod_suffix"):$2 "${@:3}" kubectl cp "$2" -n $("$cmdname" pod "$1$pod_suffix"):$2 "${@:3}"
"$cmdname" ls "$1" "${@:3}";; "$cmdname" ls "$1" "${@:3}";;
(exec) "$cmdname" kube exec "$@";; (exec) "$cmdname" kube exec "$@";;
(logs) podname=$1 (logs) test $# -gt 0 || { echo "$0 $command <pod> [lnav-args...]"; return; }
podname="$1"
shift shift
"$cmdname" kube logs "$podname" -f | $(command which ${LOGPAGER:-lnav} || { which bat >/dev/null && echo "bat --number -l toml" } || echo 'less -RF') "$@";; "$cmdname" kube logs "$podname" -f | $(command which ${LOGPAGER:-lnav} || { which bat >/dev/null && echo "bat --number -l toml" } || echo 'less -RF') "$@";;
# low-level # low-level
@ -299,6 +321,11 @@ stack() {
return $code return $code
fi fi
;; ;;
(clean-pods)
kubectl get pods --all-namespaces --no-headers |
egrep -iv 'PodInitializing|Running|ContainerCreating|Terminating' |
awk '{print "--namespace=" $1 " " $2}' |
xargs -L 1 kubectl delete pod;;
# stackspin bare # stackspin bare
(*) if which "$cmdname-$command" >/dev/null 2>&1 (*) if which "$cmdname-$command" >/dev/null 2>&1
then "$cmdname-$command" "$@" then "$cmdname-$command" "$@"