bashrc/.bashrc.d/01-env.bashrc

167 lines
4.8 KiB
Plaintext
Raw Normal View History

2023-03-18 12:49:08 +01:00
#!/usr/bin/env bash
# executed by bash(1) for non-login shells.
# ==============================
# ENV
# ==============================
# ==============================
# System
# ==============================
# Expanding PATH with system's bins
if [[ -d "/usr/sbin" ]] ; then
export PATH="/usr/sbin:$PATH"
fi
if [[ -d "/usr/local/sbin" ]] ; then
export PATH="/usr/local/sbin:$PATH"
fi
# Expanding PATH with users bin
if [[ -d "$HOME/.local/bin" ]] ; then
export PATH="$HOME/.local/bin:$PATH"
fi
# Check if XDG environment variables are set or set them to default
2023-03-19 09:38:34 +01:00
if command -v xdg-user-dir 1> /dev/null; then
if [[ -z "$XDG_DATA_HOME" ]]; then
export XDG_DATA_HOME=$HOME/.local/share
fi
if [[ -z "$XDG_CONFIG_HOME" ]]; then
export XDG_CONFIG_HOME=$HOME/.config
fi
if [[ -z "$XDG_STATE_HOME" ]]; then
export XDG_STATE_HOME=$HOME/.local/state
fi
if [[ -z "$XDG_CACHE_HOME" ]]; then
export XDG_CACHE_HOME=$HOME/.cache
fi
# Check presence of locale Download folder or create a default one
if [[ "$(xdg-user-dir DOWNLOAD)" == "$(xdg-user-dir)" ]]; then
mkdir -p "$HOME/Downloads"
export XDG_DOWNLOAD_DIR="$HOME/Downloads"
else
XDG_DOWNLOAD_DIR="$(xdg-user-dir DOWNLOAD)"
export XDG_DOWNLOAD_DIR
fi
2023-03-18 12:49:08 +01:00
fi
# ==============================
# Shell
# ==============================
# add a preview for commands and a toggle bind for FZF's history
if command -v fzf 1> /dev/null; then
export FZF_CTRL_R_OPTS="--preview 'echo {}' --preview-window down:4:wrap --bind 'ctrl-p:toggle-preview'"
fi
# vim a global text editor
if command -v vim 1> /dev/null; then
export EDITOR=vim
fi
# ==============================
# Languages
# ==============================
# Cargo env config
if [[ -d "$HOME/.cargo/bin" ]]; then
export PATH="$HOME/.cargo/bin:$PATH"
fi
# Nim env config
if [[ -d "$HOME/.nimble/bin" ]]; then
export PATH="$HOME/.nimble/bin:$PATH"
fi
# Go env config
if [[ -d "$HOME/go/bin" ]]; then
export PATH="$HOME/go/bin:$PATH"
fi
# Deno env config
if [[ -f "$HOME/.deno/bin/deno" ]]; then
export DENO_INSTALL="$HOME/.deno"
export PATH="$DENO_INSTALL/bin:$PATH"
fi
# Expanding PYTHONPATH for PDM
if command -v pdm 1> /dev/null; then
# update with output from here when upgrading Python : eval "$(pdm --pep582)"
if [[ -n "$PYTHONPATH" ]] && [[ -d "/usr/lib/python3/dist-packages/pdm/pep582" ]]; then
export PYTHONPATH='/usr/lib/python3/dist-packages/pdm/pep582':$PYTHONPATH
elif [[ -d "/usr/lib/python3/dist-packages/pdm/pep582" ]]; then
export PYTHONPATH='/usr/lib/python3/dist-packages/pdm/pep582'
fi
fi
# PIPX env config
if command -v pipx 1> /dev/null; then
eval "$(register-python-argcomplete pipx)"
fi
# refuser l'adhésion à la télémétrie .NET
if command -v dontnet 1> /dev/null; then
export DOTNET_CLI_TELEMETRY_OPTOUT=1
fi
# ==============================
# Applications
# ==============================
# Enable key bindings for fzf
if command -v fzf 1> /dev/null && [[ -f "/usr/share/doc/fzf/examples/key-bindings.bash" ]]; then
source /usr/share/doc/fzf/examples/key-bindings.bash
fi
# Let gpg-agent know from which terminal its has been called.
if command -v gpg 1> /dev/null; then
export GPG_TTY=$(tty)
fi
# set SSH Agent socket for KeepassXC
if [[ -z "$SSH_CONNECTION" ]] && command -v keepassxc 1> /dev/null; then
SSH_AUTH_SOCK=$(find /tmp/ -path "/tmp/ssh-*/agent.*" -printf "%TY-%Tm-%Td_%TH:%TM:%TS %p\n" 2>/dev/null | sort -n | tail -1 | awk '{print $2}')
export SSH_AUTH_SOCK
fi
# preprocessor for less used in neomutt
if command -v lesspipe.sh 1> /dev/null; then
export LESSOPEN="|LESSQUIET=1 /usr/local/bin/lesspipe.sh %s"
export MAGIC="/usr/share/file/magic:$HOME/.local/share/file/magic"
fi
# additional cfgs for hl
if command -v hl 1> /dev/null; then
export HL_CONF=$HOME/.config/hl/config.d:/etc/hl/config.d
fi
# used by functions mark/unmark/marks/jump
if [[ -d "$HOME/.marks" ]]; then
export MARKPATH="$HOME/.marks"
else
mkdir "$HOME/.marks"
export MARKPATH="$HOME/.marks"
fi
2023-03-30 09:09:28 +02:00
if command -v calibre 1> /dev/null; then
export CALIBRELIBRARY=$HOME/Livres/calibre
fi
2023-03-18 12:49:08 +01:00
# ==============================
# DISPLAY
# ==============================
#some fancy, colorful manpages
export LESS_TERMCAP_so=$(printf '\e[01;33m') # enter standout mode yellow
export LESS_TERMCAP_se=$(printf '\e[0m') # leave standout mode
export LESS_TERMCAP_us=$(printf '\e[04;36m') # enter underline mode cyan
export LESS_TERMCAP_ue=$(printf '\e[0m') # leave underline mode
export LESS_TERMCAP_mb=$(printf '\e[05;31m') # enter blinking mode red
export LESS_TERMCAP_md=$(printf '\e[01;35m') # enter double-bright mode bold, magenta
export LESS_TERMCAP_me=$(printf '\e[0m') # turn off all appearance modes (mb, md, so, us)
# colored GCC warnings and errors
export GCC_COLORS='error=01;31:warning=01;35:note=01;36:caret=01;32:locus=01:quote=01'