Last active
November 10, 2023 09:55
-
-
Save ninlith/e1ca1e0d02c95a765a188a501232d5c6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
HISTSIZE=1000000 | |
HISTFILESIZE=1000000 | |
HISTCONTROL=ignoreboth | |
shopt -s histappend | |
shopt -s histreedit | |
shopt -s histverify | |
PROMPT_COMMAND="history -a; history -c; history -r; $PROMPT_COMMAND" | |
PATH=$PATH:~/bin | |
PATH=$PATH:~/.local/bin | |
PATH=$PATH:~/Sync/bin | |
alias apt-fzf='apt-cache pkgnames | fzf --multi --color=border:#FFFFFF \ | |
--cycle --reverse --preview "apt-cache show {1}"' | |
apt() { | |
if [[ "$1" == @(search|list) ]]; then | |
unbuffer apt $@ | less --raw-control-chars --quit-if-one-screen | |
else | |
command apt $@ | |
fi | |
} | |
dnf() { | |
echo -e "\033[0;36m--cacheonly\033[0m" | |
command dnf --cacheonly $@ | |
} | |
ll-resolve() { | |
systemd-resolve --protocol=llmnr-ipv6 "$@" | grep "fe80::" | cut -d " " -f 2 | |
} | |
ssh-tmux() { | |
session=${session:-default} | |
ssh_arguments="" | |
while [ $# -gt 0 ]; do | |
if [[ $1 == "--link-local" ]]; then | |
ssh_arguments="$ssh_arguments $(ll-resolve $2)" | |
shift | |
elif [[ $1 == *"--"* ]]; then | |
param="${1/--/}" | |
declare $param="$2" | |
shift | |
else | |
ssh_arguments="$ssh_arguments $1" | |
fi | |
shift | |
done | |
ssh_arguments=${ssh_arguments##*( )} # trim from beginning | |
ssh "$ssh_arguments" -t "tmux attach -t $session || tmux new -s $session" | |
} | |
_ssh-tmux() | |
{ | |
local cur prev hostnames | |
cur=${COMP_WORDS[COMP_CWORD]} | |
prev=${COMP_WORDS[COMP_CWORD-1]} | |
hostnames="" | |
case ${COMP_CWORD} in | |
1) | |
COMPREPLY=($(compgen -W "--session --link-local" -- ${cur})) | |
;; | |
2) | |
case ${prev} in | |
--link-local) | |
readarray -t hostnames < <(avahi-browse --cache \ | |
--parsable --no-db-lookup --terminate \ | |
--domain local _ssh._tcp | cut -d ";" -f 4 | sort -u) | |
COMPREPLY=($(compgen -W "${hostnames[*]}" -- ${cur})) | |
;; | |
esac | |
;; | |
*) | |
COMPREPLY=() | |
;; | |
esac | |
} | |
complete -F _ssh-tmux ssh-tmux |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment