From a04bebc3c33cc969eba03e74a91ddea6b4746553 Mon Sep 17 00:00:00 2001 From: Robert Günzler Date: Wed, 30 Apr 2025 13:20:40 +0200 Subject: update .bashrc MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Robert Günzler --- .bashrc | 164 +++++++++++++++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 132 insertions(+), 32 deletions(-) (limited to '.bashrc') diff --git a/.bashrc b/.bashrc index 3b30946..8979f1d 100644 --- a/.bashrc +++ b/.bashrc @@ -1,3 +1,4 @@ +# vim: ft=bash # /etc/skel/.bashrc # # This file is sourced by all *interactive* bash shells on startup, @@ -5,16 +6,11 @@ # that can't tolerate any output. So make sure this doesn't display # anything or bad things will happen ! -safe_load() { +function safe_load() { sh="$1" [ -r "$sh" ] && . "$sh" unset sh } -prepend_prompt_command() { - if [[ ${PROMPT_COMMAND:=} != *${1}* ]]; then - PROMPT_COMMAND="${1};${PROMPT_COMMAND#;}" - fi -} # Test for an interactive shell. There is no need to set anything # past this point for scp and rcp, and it's important to refrain from @@ -34,9 +30,11 @@ shopt -s histappend #HISTFILESIZE=500000 HISTCONTROL=ignorespace +declare -a _userfuncs + # OSC7 escapte sequence # https://codeberg.org/dnkl/foot/wiki#spawning-new-terminal-instances-in-the-current-working-directory -_osc7_cwd() { +function _osc7_cwd() { local strlen=${#PWD} local encoded="" local pos c o @@ -50,60 +48,162 @@ _osc7_cwd() { done printf '\e]7;file://%s%s\e\\' "${HOSTNAME}" "${encoded}" } -prepend_prompt_command _osc7_cwd +_userfuncs+=(_osc7_cwd) # OSC133 command prompt marker # https://codeberg.org/dnkl/foot/wiki#jumping-between-prompts -_osc133_marker() { +function _osc133_prompt_marker() { printf '\e]133;A\e\\' } -prepend_prompt_command _osc133_marker +_userfuncs+=(_osc133_prompt_marker) # set window title -_set_win_title() { - printf '\033]0;%s\007' "${PWD} (${HOSTNAME}) - FOOT" +function _osc0_set_win_title() { + printf '\033]0;%s\007' "${PWD} (${HOSTNAME}) - ${TERM}" +} +_userfuncs+=(_osc0_set_win_title) + +# append to HISTFILE on every prompt +function _histappend() { + builtin history -a } -prepend_prompt_command _set_win_title +_userfuncs+=(_histappend) + +# assign precmds to the precmds array above this line! +function _userfuncs_exec() { + IFS=';' + eval "${_userfuncs[*]}" +} + +# TODO: when using starship we need to use it's precmd helpers to avoid +# breaking the status module +if [ -x "$(command -v starship)" ]; then + starship_precmd_user_func="_userfuncs_exec" +else + [[ ${PROMPT_COMMAND:=} != *_userfuncs_exec* ]] && + PROMPT_COMMAND="_userfuncs_exec;${PROMPT_COMMAND#;}" +fi # Alias shell commands -# alias logout='dbus-send --session --type=method_call --print-reply --dest=' -alias ..='cd ..' -alias balscp='scp -P 22222 -o User=root -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -o Compression=yes' -alias balssh='ssh -p 22222 -o User=root -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -o Compression=yes' -#alias cat=bat +# alias logout="dbus-send --session --type=method_call --print-reply --dest=" +alias ..="cd .." +alias balscp="scp -P 22222 -o User=root -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -o Compression=yes" +alias balssh="ssh -p 22222 -o User=root -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -o Compression=yes" +alias c=clifm +alias cat=bat +alias clear='printf "\033[H\033[2J"' alias dao=doas alias daos=doas alias daso=doas +alias dbx=distrobox +alias diffconfig='doas /usr/src/linux/scripts/diffconfig' alias dosa=doas -alias fm=vifm +alias droidcam-cli="doas modprobe v4l2loopback && doas droidcam-cli" +alias f=fzfez +alias fm="swallow /home/robert/src/fm/target/release/fm" alias g=git -alias grep='grep --color=auto' +alias grep="grep --color=auto" alias k=kubectl -alias l="eza --long --classify --inode --group --header --group-directories-first --time-style=long-iso" -alias lt="eza --classify --group-directories-first -T" +alias l="eza --long --classify --inode --group --header --group-directories-first --time-style=long-iso --git" +alias lt="eza --classify --group-directories-first --git -T" +alias mk=make +alias ni=ninja alias nv=nvim -alias org='nvim +Orgmode' -alias rm=saferm +alias open="xdg-open" +alias org="nvim +Orgmode" +alias pandoc="pandoc -d \${HOME}/.config/pandoc.yml" +alias py=python +alias rip='trash-put' +alias rm='rm -i' alias rsy=rsyncez -alias srv='rclone serve http --addr=0.0.0.0:8080 .' -alias ssh='TERM=xterm-256color ssh' +alias srv="rclone serve http --addr=0.0.0.0:8080" +alias ssh="TERM=xterm-256color ssh" alias suspend=loginctl\ suspend -alias tt=timetrace +alias tt=timew +alias tw=timew alias v=nvim +alias vi=nvim alias vim=nvim alias wlc=wl-copy alias wlp=wl-paste +alias mpa="mpv --no-video" +alias zb="zig build" + +export BAT_THEME=base16-256 +# export DOCKER_BUILDKIT=1 +export DOCKER=podman +export ENTER_DRIVER=$DOCKER +# set default editor +export EDITOR=nvim +export VISUAL=$EDITOR +# configure gpg-agent +export GPG_TTY=$(tty) +# Set less default options +export LESS='--hilite-search --hilite-unread --long-prompt --raw-control-chars --chop-long-lines --quit-if-one-screen --no-init' +export PAGER='ov' +export MANPAGER='ov' +# export PAGER='page -WC -q 90000 -z 90000' +# export MANPAGER='page -t man' + +# Set the rsync ssh command to use by default +export RSYNC_RSH='ssh -T -x -o Compression=no' +# Use the new build backend in docker +# zettelkasten +export ZK_NOTEBOOK_DIR=${HOME}/zettelkasten +export ZK_JOURNAL_DIR=500_journals # enable direnv [ -x "$(command -v direnv)" ] && eval "$(direnv hook bash)" -# enable navi -[ -x "$(command -v navi)" ] && eval "$(navi widget bash)" -# enable zoxide -[ -x "$(command -v zoxide)" ] && eval "$(zoxide init bash)" + +# enable todo +[ -x "$(command -v todo)" ] && eval "$(todo hook bash)" + # enable starship +# NOTE: eval this last, to avoid losing PROMPT_COMMAND [ -x "$(command -v starship)" ] && eval "$(starship init bash)" + # Use keychain to reuse the ssh-agent and gpg-agent between logins -[ -x "$(command -v keychain)" ] && eval "$(keychain --eval --agents ssh,gpg -q id_ed25519)" # AF6AB8C8B10436B9F61293632143BD2AAB94BCC4 +# [ -x "$(command -v keychain)" ] && eval "$(keychain --eval --agents ssh,gpg -q id_ed25519)" # AF6AB8C8B10436B9F61293632143BD2AAB94BCC4 # safe_load "$HOME/.keychain/$(hostname)-sh" # safe_load "$HOME/.keychain/$(hostname)-sh-gpg" + +# enable fzf ctrl-r +# exit ctrl-r early +export FZF_DEFAULT_OPTS="--bind=shift-tab:replace-query" +export FZF_CTRL_R_OPTS="--layout=reverse --bind=ctrl-space:print-query" +# predefine compgen helpers using ripgrep and fd +_fzf_compgen_path() { rg --files --glob "!.git" . "$1"; } +_fzf_compgen_dir() { fd --type d --hidden --follow --exclude ".git" . "$1"; } +# register completions for some additional commands safe_load /usr/share/fzf/key-bindings.bash +safe_load /usr/share/bash-completion/completions/fzf + +## populate PATH +. /etc/profile.d/path_func.sh + +[ -d "${HOME}/bin/$(uname -n)" ] && pathprepend "${HOME}/bin/$(uname -n)" +[ -d "${HOME}/zettelkasten/bin" ] && pathappend "${HOME}/zettelkasten/bin" + +export GOPATH="${HOME}/go" +if [ -d "${GOPATH}" ]; then + pathappend "${GOPATH}/bin" +fi + +if [ -d "${HOME}/.cargo/bin" ]; then + pathappend "${HOME}/.cargo/bin" +fi + +# enable sccache globally +# export RUSTC_WRAPPER=/usr/bin/sccache +# export SCCACHE_DIR=/var/tmp/sccache +# export SCCACHE_MAX_FRAME_LENGTH=104857600 + +export SSH_ASKPASS=${HOME}/bin/askpass +export SSH_ASKPASS_REQUIRE=prefer + +# enable zoxide +[ -x "$(command -v zoxide)" ] && eval "$(zoxide init bash)" + +# enable broot +[ -x "$(command -v broot)" ] && source "${HOME}/.config/broot/launcher/bash/br" +source "$HOME/.cargo/env" -- cgit 1.4.1