From f09fce4ff51ff3e26a4d77b23ca34950c9162fc0 Mon Sep 17 00:00:00 2001 From: Raymaekers Luca Date: Tue, 12 Dec 2023 17:21:11 +0100 Subject: use seperate shell folder that works cross shells --- config/essentials/shell/functions.sh | 306 +++++++++++++++++++++++++++++++++++ 1 file changed, 306 insertions(+) create mode 100644 config/essentials/shell/functions.sh (limited to 'config/essentials/shell/functions.sh') diff --git a/config/essentials/shell/functions.sh b/config/essentials/shell/functions.sh new file mode 100644 index 0000000..37e471c --- /dev/null +++ b/config/essentials/shell/functions.sh @@ -0,0 +1,306 @@ +#!/bin/sh + +log() { >&2 printf '%s' "$@"; } +logn() { >&2 printf '%s\n' "$@"; } + +vmp() { + col -b | \ + vim -MR \ + -c 'set ft=man nolist nonu nornu' +} +nvf() { + cache="$HOME/.cache/nvf" + match="$(grep -m1 "$1$" "$cache" 2> /dev/null)" + if test ! -f "$match" + then + logn "resetting cache..." + match="$(goo f "$HOME" | tee "$cache" | grep -m 1 "$1$" 2> /dev/null)" + # # Alternative: + # match="$(goo | grep -m 1 "$1" 2> /dev/null | tee -a | "$cache")" + fi + if test -f "$match" + then + $EDITOR "$match" && return + else + logn "no match." && return 1 + fi +} + +nnn() { test -z "$NNNLVL" && /usr/bin/nnn "$@" || exit; } +ranger() { test -z "$RANGER_LEVEL" && /usr/bin/ranger "$@" || exit; } + +# googoo aliases +_googoo_fzf_opt() +{ + unset dest opt + if [ "$1" ] + then + [ -d "$1" ] && dest="$1" || opt="-q $1" + fi +} +o() +{ + _googoo_fzf_opt "$1" + f="$(goo f "$dest" | fzf $opt)" + test "$1" && shift + test -f "$f" && $EDITOR $@ "$f" +} +go() +{ + _googoo_fzf_opt "$1" + cd "$(goo d "$dest" | fzf $opt)" +} +ogo() +{ + _googoo_fzf_opt "$1" + cd "$(dirname "$(goo f "$dest" | fzf $opt)")" +} + +# Onelineres +awnk() { awk "{print \$$1}"; } +vimh() { vi -c "help $1" -c 'call feedkeys("\o")'; } +dgo() { cd "$(goo d ~ | fzf --filter "$@" | head -n 1)"; } +open() { $EDITOR "$(goo f ~ | fzf --filter "$@" | head -n 1)"; } +pkbs() { doas pacman -Sy "$(pkgfile -b "$1" | tee /dev/stderr)"; } +oclip() { printf "\033]52;c;$(printf '%s' "$@" | base64)\a"; } +sms() { ssh -t phone sendmsg "$1" "'$2'"; } +trcp() { scp "$1" db:/media/basilisk/downloads/transmission/torrents/; } +rln() { ln -s "$(readlink -f "$1")" "$2"; } +getgit() { git clone git@db:"$1"; } + +ipc() +{ + if [ "$(ip link show eno1 | awk -F, 'NR=1 {print $3}')" = "UP" ] + then + doas ip link set eno1 down + else + doas ip link set eno1 up + fi +} + +psgrep() +{ + [ $# -eq 0 ] && return 1 + pgrep "$@" | xargs ps +} + +unique() { + f="$(mktemp)" + awk '!x[$0]++' "$1" > "$f" + mv "$f" "$1" +} + +clip() { + if [ "$WAYLAND_DISPLAY" ] + then + echo -n "$@" | wl-copy + else + echo -n "$@" | xclip -selection clipboard -rmlastnl + fi +} + +unzipp() { + unzip -- "$(readlink -f -- "$1")" || return 1 + rm -- "$1" +} + +# fix long waiting time +__git_files() { + _wanted files expl 'local files' _files +} + +esc() { + $EDITOR "$(which $1)" +} + +delfile() { + curl "${2:-https://upfast.cronyakatsuki.xyz/delete/$1}" +} +upfile() { + curl -F "file=@\"$1\"" ${2:-https://0x0.st} +} + +# git +sgd() { + d="$PWD" + find $HOME/src -maxdepth 1 -mindepth 1 -type d | + while read -r dir + do + cd "$dir" + git status > /dev/null 2>&1 || continue + git fetch > /dev/null 2>&1 + printf "$PWD" + test "$(git status --short 2>/dev/null | grep -v "??" | head -1)" && + printf " \e[1;31m*changes\e[0m" | sed "s#$HOME#~#" >&2 + test "$(parse_git_remote)" && + printf " \e[0;32m*push/pull\e[0m" | sed "s#$HOME#~#" >&2 + printf "\n" + done + cd "$d" + unset d +} + +ginit() +{ + [ "$1" ] || return 1 + ssh db /var/git/initdir.sh "$1" + git remote add origin git@db:"$1.git" + git push --set-upstream origin $(git_current_branch) +} + +# Returns current branch +git_current_branch() +{ + command git rev-parse --git-dir > /dev/null 2>&1 || return + git branch --show-current +} + +# Check if main exists and use instead of master +git_main_branch() +{ + command git rev-parse --git-dir > /dev/null 2>&1 || return + for ref in refs/{heads,remotes/{origin,upstream}}/{main,trunk,mainline,default} + do + if command git show-ref -q --verify $ref; then + echo ${ref:t} + return + fi + done + echo master +} + +# Check for develop and similarly named branches +function git_develop_branch() { + command git rev-parse --git-dir > /dev/null 2>&1 || return + for branch in dev devel development + do + if command git show-ref -q --verify refs/heads/$branch + then + echo $branch + return + fi + done + echo develop +} + +# gpg backup +gpg_backup() +{ + # $1: option + # $2: output file (without .asc) + gpg_command() { gpg "$1" --armor > "$2".asc; } + gpg_command --export-secret-keys "private" + gpg_command --export "public" + gpg_command --export-ownertrust "trust" + tar -czvf gpg_backup.tar.gz public.asc private.asc trust.asc + shred -uz public.asc private.asc trust.asc +} + +gpg_import() +{ + tar xf $1 + shred -uz $1 + gpg --import public.asc + gpg --import-ownertrust trust.asc + gpg --import private.asc + shred -uz public.asc private.asc trust.asc +} + +ngenable() +{ + ln -sf /etc/nginx/sites-available/$1 /etc/nginx/sites-enabled/ +} + +vbsr() +{ + vboxmanage snapshot "$1" restore "$2" && + vboxmanage startvm "$1" || + vboxmanage controlvm "$1" poweroff +} +vbsrr() +{ + vbsr "$1" "$2" + sleep 3 + vbsr "$1" "$2" +} +vbst() +{ + vboxmanage snapshot "$1" take "$2" +} + +pacsize() +{ + if test -n "$1"; then + packages="$@" + elif test ! -t 0; then + packages="$(cat)" + else + echo "No data provided..." + return 1 + fi + echo $packages | + expac '%m %n' - | + numfmt --to=iec-i --suffix=B --format="%.2f" +} + +mime-default () +{ + [ "${mime:=$1}" ] || + mime="$(find /usr/share/applications/ -iname '*.desktop' -printf '%f\n' | + sed 's/\.desktop$//' | + fzf)" + + logn "Setting '$mime' as default for its mimetypes" + [ "$mime" ] || exit 1 + grep "MimeType=" /usr/share/applications/"$mime".desktop | + cut -d '=' -f 2- | tr ';' '\0' | + xargs -0I{} xdg-mime default "$mime".desktop "{}" + logn "Done." +} + +addedkeys() { + find ~/.ssh -iname "*.pub" | while read key + do + fingerprint="$(ssh-keygen -lf "$key" 2>/dev/null)" + if ssh-add -l | grep -q "$fingerprint" + then + echo "$key" + fi + done | sed "s,$HOME/.ssh/,," +} + +fpass() { + find $HOME/.password-store -type f -not -path ".git" | + grep "\.gpg$" | + sed "s,$HOME/.password-store/,,;s,\.gpg$,," | + fzf | + xargs pass show -c +} + +muttmail() +{ + config="$HOME/.config/mutt" + mail="$(find "$config"/configs -type f -printf '%f\n' | fzf)" + [ "$mail" ] || return 1 + ln -sf "$config/configs/$mail" "$config"/muttrc + mutt +} + +resize() +{ + test $# -lt 2 && + printf "usage: %s [out]\n" "$0" >&2 && + return 1 + convert -resize $1^ -gravity center -crop $1+0+0 -- "$2" "${3:-$1}" +} + +edit_in_dir() { + file="$1/$(goo f "$1" | sed "s@^$1@@" | fzf)" + [ -f "$file" ] || return 1 + $EDITOR "$file" +} + +to_webm() +{ + ffmpeg -y -i "$1" -vcodec libvpx -cpu-used -12 -deadline realtime "${1%.*}".webm +} -- cgit v1.2.3 From 82fe753f3dd60d358ee399ff7ac5740f849a1741 Mon Sep 17 00:00:00 2001 From: Raymaekers Luca Date: Wed, 3 Jan 2024 16:07:17 +0100 Subject: update --- bin/common/ytclipo | 4 ++-- config/essentials/git/config | 7 ++++++- config/essentials/shell/aliases.sh | 2 +- config/essentials/shell/functions.sh | 2 +- config/essentials/zsh/.zshrc | 2 +- config/home/.bashrc | 4 +++- config/home/.zshenv | 4 ++-- config/theme/fontconfig/fonts.conf | 3 ++- 8 files changed, 18 insertions(+), 10 deletions(-) (limited to 'config/essentials/shell/functions.sh') diff --git a/bin/common/ytclipo b/bin/common/ytclipo index 1a82df2..6416a15 100755 --- a/bin/common/ytclipo +++ b/bin/common/ytclipo @@ -2,7 +2,7 @@ inp="$(ytlink)" >&2 printf "inp: %s\n" "$inp" -notify-send "ytclipo" "downloading $inp" || : +# notify-send "ytclipo" "downloading $inp" || : yt-dlp "$inp" \ --restrict-filenames \ @@ -11,4 +11,4 @@ yt-dlp "$inp" \ -S "res:1080" \ -P "$HOME/vids/youtube/" \ -o "%(channel)s/%(title)s.%(ext)s" -notify-send "ytclipo" "finished downloading." || : +# notify-send "ytclipo" "finished downloading." || : diff --git a/config/essentials/git/config b/config/essentials/git/config index 90bab4f..fcf80db 100644 --- a/config/essentials/git/config +++ b/config/essentials/git/config @@ -3,5 +3,10 @@ [user] email = raymaekers.luca@gmail.com name = Raymaekers Luca + signingkey = 3A626DD20A32EB2E5DD9CE71CFD9ABC97158CD5D [push] - autoSetupRemote = true + autosetupremote = true +[pull] + rebase = false +[commit] + gpgsign = true diff --git a/config/essentials/shell/aliases.sh b/config/essentials/shell/aliases.sh index eed3fa0..99c49d8 100644 --- a/config/essentials/shell/aliases.sh +++ b/config/essentials/shell/aliases.sh @@ -140,7 +140,7 @@ alias ss4='ss -tln4p' alias mdb='mariadb -u admin -ppass admindb' alias mdbw='mariadb -h 0.0.0.0 -u padmin -pbulbizarre padmindb' alias mdbwa='mariadb -h 10.3.50.5 -u padmin -pbulbizarre padmindb' -alias tmux='tmux a || tmux' +alias tmux='pgrep tmux && tmux attach || tmux new-session' # ssh alias sha='ssh-add' diff --git a/config/essentials/shell/functions.sh b/config/essentials/shell/functions.sh index 37e471c..b699a86 100644 --- a/config/essentials/shell/functions.sh +++ b/config/essentials/shell/functions.sh @@ -110,7 +110,7 @@ __git_files() { } esc() { - $EDITOR "$(which $1)" + eval "$EDITOR '$(which $1)'" } delfile() { diff --git a/config/essentials/zsh/.zshrc b/config/essentials/zsh/.zshrc index 2223c67..99c65d7 100644 --- a/config/essentials/zsh/.zshrc +++ b/config/essentials/zsh/.zshrc @@ -153,7 +153,7 @@ command_not_found_handler () { } # prompt -PS1=' %B%(#.%F{1}.%F{13})%n%b%f@%B%F{6}%m%b%f %3~ ' +PS1=' %K{16}%B%(#.%F{1}.%F{13})%n%b%f@%B%F{6}%m%b%f %3~%k ' RPROMPT='%F{blue}$(parse_git_remote)%f%F{red}$(parse_git_status)%f%F{green}$(parse_git_branch)%f%(?.. %?)' setopt prompt_subst diff --git a/config/home/.bashrc b/config/home/.bashrc index de7659a..312500d 100644 --- a/config/home/.bashrc +++ b/config/home/.bashrc @@ -2,9 +2,11 @@ SHELL=/bin/bash PATH=$HOME/bin:$PATH color1="\[\033[35m\]" color2="\[\033[36m\]" +color3="\[\033[40m\]" +color4="\[\033[38m\]" bold="\[\033[1m\]" reset="\[\033[0m\]" -PS1="${color1}${bold} [\\u${reset}@${color2}${bold}\\h]${reset} \\w " +PS1="${color1}${bold} ${color3}\\u${reset}${color3}${color4}@${color2}${bold}\\h${reset}${color3} \\w${reset} " HISTFILE= . $HOME/.config/shell/aliases.sh . $HOME/.config/shell/functions.sh diff --git a/config/home/.zshenv b/config/home/.zshenv index d33fbd7..e8021ec 100644 --- a/config/home/.zshenv +++ b/config/home/.zshenv @@ -1,6 +1,6 @@ #!/bin/zsh -export EDITOR="emacsclient -t" -export VISUAL="emacsclient -t -c -a emacs" +export EDITOR="emacsclient -nw -q" +export VISUAL="emacsclient -nw -q" export BROWSER="librewolf" export VIEWER="zathura" diff --git a/config/theme/fontconfig/fonts.conf b/config/theme/fontconfig/fonts.conf index 8681e4e..625dd34 100644 --- a/config/theme/fontconfig/fonts.conf +++ b/config/theme/fontconfig/fonts.conf @@ -16,7 +16,8 @@ monospace - JetBrains Mono + JetBrains Mono + JetBrains Mono NerdFont Joy Pixels -- cgit v1.2.3