1
0
Fork 0

fish, zsh: functions

This commit is contained in:
Von Random 2024-11-11 12:21:02 +02:00
parent a8e215506a
commit 1dc616297a
6 changed files with 53 additions and 37 deletions

View file

@ -0,0 +1,3 @@
function k
command kubectl $argv
end

View file

@ -0,0 +1,3 @@
function kc
command kubectl config $argv
end

View file

@ -0,0 +1,3 @@
function kg
command kubectl get $argv
end

View file

@ -0,0 +1,3 @@
function kshell
command kubectl exec -n "$1" --stdin --tty "$2" -- /bin/sh
end

View file

@ -0,0 +1,3 @@
function ksw
command kubecm switch $argv
end

View file

@ -1,9 +1,9 @@
# Fuck default aliases # Fuck default aliases
unalias -a unalias -a
testbin() { whence $@ > /dev/null } function testbin { whence $@ > /dev/null }
termcompat() { function termcompat {
typeset term=$TERM typeset term=$TERM
case $term in case $term in
(alacritty*) ;& (alacritty*) ;&
@ -19,7 +19,7 @@ termcompat() {
TERM=$term command $@ TERM=$term command $@
} }
addpath() { function addpath {
typeset newpath=$1 typeset newpath=$1
if [[ ! $PATH =~ $newpath ]]; then if [[ ! $PATH =~ $newpath ]]; then
PATH+=:$newpath PATH+=:$newpath
@ -27,41 +27,42 @@ addpath() {
fi fi
} }
fsf() { function fsf {
typeset host prompt="SSH Remote > " typeset host prompt="SSH Remote > "
host=$(cut -d\ -f1 $HOME/.ssh/known_hosts | sort -u | fzf --prompt=$prompt) || return 1 host=$(cut -d\ -f1 $HOME/.ssh/known_hosts | sort -u | fzf --prompt=$prompt) || return 1
termcompat ssh $host $@ termcompat ssh $host $@
} }
beep() { printf $'\007' } function beep { printf $'\007' }
fixterm() { printf $'\u001bc' } function fixterm { printf $'\u001bc' }
diff() { command diff --color $@ } function diff { command diff --color $@ }
tailf() { command less +F $@ } function tailf { command less +F $@ }
grep() { command grep --color=auto $@ } function grep { command grep --color=auto $@ }
rgrep() { grep --exclude-dir=.git -R $@ } function rgrep { grep --exclude-dir=.git -R $@ }
s() { termcompat ssh $@ } function s { termcompat ssh $@ }
if testbin nvim; then function tmux { command tmux -2 $@ }
vi() { command nvim $@ } function atmux { tmux attach || tmux }
vim() { command nvim $@ }
fi
tmux() { command tmux -2 $@ } function ksw { command kubecm switch $@ }
atmux() { tmux attach || tmux } function k { command kubectl $@ }
function kg { command kubectl get $@ }
function kc { command kubectl config $@ }
function kshell { command kubectl exec -n $1 --stdin --tty $2 -- /bin/sh }
g() { command lazygit $@ } function g { command lazygit $@ }
gci() { command git commit $@ } function gci { command git commit $@ }
gsl() { command git stash list $@ } function gsl { command git stash list $@ }
gss() { command git status -sbu $@ } function gss { command git status -sbu $@ }
gsw() { command git switch $@ } function gsw { command git switch $@ }
gup() { command git pull $@ } function gup { command git pull $@ }
gwta() { command git worktree add $@ } function gwta { command git worktree add $@ }
gwtp() { command git worktree prune -v } function gwtp { command git worktree prune -v }
groot() { cd $(command git rev-parse --show-toplevel) || return 0 } function groot { cd $(command git rev-parse --show-toplevel) || return 0 }
gdiff() { command git diff --color $@ } function gdiff { command git diff --color $@ }
greset() { function greset {
echo "OK to reset and clean teh repo?" echo "OK to reset and clean teh repo?"
read -sq _ read -sq _
(( $? )) && return 1 (( $? )) && return 1
@ -70,19 +71,19 @@ greset() {
} }
if testbin diff-so-fancy; then if testbin diff-so-fancy; then
gdf() { gdiff $@ | command diff-so-fancy | command less --tabs=4 -RSFX } function gdf { gdiff $@ | command diff-so-fancy | command less --tabs=4 -RSFX }
else else
gdf() { gdiff $@ } function gdf { gdiff $@ }
fi fi
if testbin eza; then if testbin eza; then
ls() { command eza --group-directories-first $@ } function ls { command eza --group-directories-first $@ }
ll() { ls -alg $@ } function ll { ls -alg $@ }
ld() { ls -dlg $@ } function ld { ls -dlg $@ }
else else
ls() { command ls --color=auto --group-directories-first $@ } function ls { command ls --color=auto --group-directories-first $@ }
ll() { ls -alh $@ } function ll { ls -alh $@ }
ld() { ls -dlh $@ } function ld { ls -dlh $@ }
fi fi
# grc # grc
@ -92,7 +93,7 @@ if testbin grc; then
mtr netstat ping ping6 ps tcpdump traceroute traceroute6 \ mtr netstat ping ping6 ps tcpdump traceroute traceroute6 \
) )
for cmd in $cmds; do for cmd in $cmds; do
eval "$cmd() { command grc -es --colour=auto $cmd \$@ }" eval "function $cmd { command grc -es --colour=auto $cmd \$@ }"
done done
unset cmds cmd unset cmds cmd
fi fi