first commit
This commit is contained in:
commit
12e96c1088
7
.bash_logout
Normal file
7
.bash_logout
Normal file
|
@ -0,0 +1,7 @@
|
|||
# ~/.bash_logout: executed by bash(1) when login shell exits.
|
||||
|
||||
# when leaving the console clear the screen to increase privacy
|
||||
|
||||
if [ "$SHLVL" = 1 ]; then
|
||||
[ -x /usr/bin/clear_console ] && /usr/bin/clear_console -q
|
||||
fi
|
3
.bash_profile
Normal file
3
.bash_profile
Normal file
|
@ -0,0 +1,3 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
. "$HOME/.profile"
|
16
.bashrc
Normal file
16
.bashrc
Normal file
|
@ -0,0 +1,16 @@
|
|||
#!/usr/bin/env bash
|
||||
# ~/.bashrc: executed by bash(1) for non-login shells.
|
||||
|
||||
# If not running interactively, don't do anything
|
||||
case $- in
|
||||
*i*) ;;
|
||||
*) return ;;
|
||||
esac
|
||||
|
||||
chmod 700 ~/.bashrc.d
|
||||
chmod 600 ~/.bashrc ~/.bashrc.d/*
|
||||
|
||||
for file in ~/.bashrc.d/*.bashrc;
|
||||
do
|
||||
source "${file}"
|
||||
done
|
68
.bashrc.d/00-shelloptions.bashrc
Normal file
68
.bashrc.d/00-shelloptions.bashrc
Normal file
|
@ -0,0 +1,68 @@
|
|||
#!/usr/bin/env bash
|
||||
# executed by bash(1) for non-login shells.
|
||||
|
||||
# ==============================
|
||||
# SHELL OPTIONS
|
||||
# ==============================
|
||||
|
||||
# shell command line style : emacs, vi, noediting
|
||||
set -o emacs
|
||||
# set -o vi
|
||||
# set –noediting
|
||||
|
||||
# exit will lists the status interactive jobs and postpone if one is running
|
||||
shopt -s checkjobs
|
||||
|
||||
# includes filenames beginning with a . (dot) in pathname expansion
|
||||
shopt -s dotglob
|
||||
|
||||
# check the window size after each command and, if necessary,
|
||||
# update the values of LINES and COLUMNS.
|
||||
shopt -s checkwinsize
|
||||
|
||||
# enable programmable completion features
|
||||
if ! shopt -oq posix; then
|
||||
if [ -f /usr/share/bash-completion/bash_completion ]; then
|
||||
. /usr/share/bash-completion/bash_completion
|
||||
elif [ -f /etc/bash_completion ]; then
|
||||
. /etc/bash_completion
|
||||
fi
|
||||
fi
|
||||
|
||||
# activate a DEBUG trap to catch term window resize
|
||||
#declare -x rows cols
|
||||
#update_size(){
|
||||
# winsizeStatus=$(shopt | grep checkwinsize | awk '{print $2}')
|
||||
# if [[ "$winsizeStatus" == "off" ]]; then
|
||||
# rows=$(tput lines)
|
||||
# cols=$(tput cols)
|
||||
# echo -en "\e[2;5;90mDEBUG\e[25;90m TERM winsize updated to ${rows}x${cols} >\e[0m"
|
||||
# else
|
||||
# echo -en "\e[2;5;90mDEBUG\e[25;90m TERM winsize updated to ${LINES}x${COLUMNS} >\e[0m"
|
||||
# fi
|
||||
#}
|
||||
#trap update_size WINCH
|
||||
|
||||
# ==============================
|
||||
# HISTORY
|
||||
# ==============================
|
||||
|
||||
# attempts to save all lines of a multiple-line command in the same history entry
|
||||
shopt -s cmdhist
|
||||
|
||||
# appended rather than overwrite
|
||||
shopt -s histappend
|
||||
|
||||
# with cmdhist, saved with embedded newlines rather than semicolon separators
|
||||
shopt -s lithist
|
||||
|
||||
HISTCONTROL=ignoreboth
|
||||
HISTSIZE=10000
|
||||
HISTFILESIZE=20000
|
||||
HISTTIMEFORMAT="%y/%m/%d %T "
|
||||
HISTIGNORE="history:ls:l:pwd:exit:"
|
||||
if [[ ${BASH_VERSION:0:1} -gt 5 || ${BASH_VERSION:0:1} -ge 5 && ${BASH_VERSION:2:1} -ge 1 ]]; then
|
||||
PROMPT_COMMAND=("history -a" "history -c" "history -r")
|
||||
else
|
||||
PROMPT_COMMAND="history -a; history -c; history -r"
|
||||
fi
|
160
.bashrc.d/01-env.bashrc
Normal file
160
.bashrc.d/01-env.bashrc
Normal file
|
@ -0,0 +1,160 @@
|
|||
#!/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
|
||||
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
|
||||
|
||||
# ==============================
|
||||
# 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
|
||||
|
||||
# ==============================
|
||||
# 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'
|
17
.bashrc.d/02-secrets.bashrc
Normal file
17
.bashrc.d/02-secrets.bashrc
Normal file
|
@ -0,0 +1,17 @@
|
|||
#!/usr/bin/env bash
|
||||
# executed by bash(1) for non-login shells.
|
||||
|
||||
# ==============================
|
||||
# SECRETS
|
||||
# ==============================
|
||||
|
||||
# for the boop function
|
||||
NTFYSERVER="ntfy.server.tld"
|
||||
export NTFYBOOPSURL="https://${NTFYSERVER}/boops"
|
||||
if command -v keyring 1> /dev/null && [[ -n "$DBUS_SESSION_BUS_ADDRESS" ]]; then
|
||||
NTFYBOOPSTOKEN="$(keyring -b keyring.backends.SecretService.Keyring get ${NTFYSERVER} boop-token)"
|
||||
export NTFYBOOPSTOKEN
|
||||
fi
|
||||
|
||||
# locale city for scripts like meteo alias
|
||||
export MYCITY="Some City"
|
215
.bashrc.d/10-aliases.bashrc
Normal file
215
.bashrc.d/10-aliases.bashrc
Normal file
|
@ -0,0 +1,215 @@
|
|||
#!/usr/bin/env bash
|
||||
# executed by bash(1) for non-login shells.
|
||||
|
||||
# ==============================
|
||||
# ALIASES
|
||||
# ==============================
|
||||
|
||||
# ==============================
|
||||
# Overlays
|
||||
# ==============================
|
||||
|
||||
if command -v dircolors 1> /dev/null; then
|
||||
alias dir='dir --color=auto'
|
||||
alias vdir='vdir --color=auto'
|
||||
|
||||
# had to add -a because grep interprete a part of syslog as a binary
|
||||
alias grep='grep --color=auto -a'
|
||||
alias fgrep='fgrep --color=auto'
|
||||
alias egrep='egrep --color=auto'
|
||||
|
||||
alias ls='ls --color=auto'
|
||||
else
|
||||
alias grep='grep -a'
|
||||
fi
|
||||
|
||||
# most common usage of df/du
|
||||
if command -v hl 1> /dev/null; then
|
||||
alias df='df -Tha --total | hlauto --df'
|
||||
else
|
||||
alias df='df -Tha --total'
|
||||
fi
|
||||
alias du='du -ach'
|
||||
|
||||
# better ncdu
|
||||
if command -v ncdu 1> /dev/null; then
|
||||
alias ncdu='ncdu -e --exclude-kernfs --color dark'
|
||||
fi
|
||||
|
||||
# nano with backups
|
||||
if command -v nano 1> /dev/null; then
|
||||
mkdir -p ~/.cache/nano/backups
|
||||
alias nano='nano -BGSceilqy% --atblanks -T 4 -C ~/.cache/nano/backups'
|
||||
# clean nano backups
|
||||
alias nano-clean='rm -rf ~/.cache/nano/backups/*'
|
||||
fi
|
||||
# force vim usage
|
||||
if command -v vim 1> /dev/null; then
|
||||
alias vi='vim'
|
||||
fi
|
||||
|
||||
# ==============================
|
||||
# New/Updated Utils
|
||||
# ==============================
|
||||
|
||||
# login to root with sudo but keeping your ssh-agent and tmux env
|
||||
alias sudoi='sudo -i --preserve-env=TMUX,WINDOWID,SSH_AGENT_PID,TERM_PROGRAM'
|
||||
|
||||
# short cd ..
|
||||
alias cd..='cd ..'
|
||||
alias ..='cd ..'
|
||||
# last location
|
||||
alias back='cd "$OLDPWD"'
|
||||
|
||||
# new upgraded ls, check fzf versions in functions
|
||||
if command -v exa 1> /dev/null; then
|
||||
alias l='exa -abghHl --git --icons --color always --group-directories-first --time-style=long-iso'
|
||||
fi
|
||||
|
||||
# most common usage of ps
|
||||
alias psf='ps faux'
|
||||
# grep in psf
|
||||
alias psg='ps faux | grep -v grep | grep -i -e VSZ -e'
|
||||
|
||||
# grep in history
|
||||
alias hgrep='history | grep -i'
|
||||
# print the 15 last lines from history
|
||||
alias recent='fc -l'
|
||||
|
||||
# mkdir verbose and recursive
|
||||
alias mkd='mkdir -pv'
|
||||
|
||||
# better man
|
||||
alias manu='man --encoding UTF-8 --no-hyphenation --pager "less --ignore-case --LONG-PROMPT --mouse --quit-at-eof --quit-if-one-screen --RAW-CONTROL-CHARS --squeeze-blank-lines --status-column --tilde --use-color"'
|
||||
|
||||
# less with follow like tail -f
|
||||
alias less-follow='less --auto-buffers --follow-name +F --ignore-case --LONG-PROMPT --mouse --quit-at-eof --RAW-CONTROL-CHARS --squeeze-blank-lines --status-column --tilde --use-color'
|
||||
|
||||
# find alternative
|
||||
if command -v fdfind 1> /dev/null; then
|
||||
alias fd='fdfind'
|
||||
alias fdh='fdfind -H'
|
||||
fi
|
||||
|
||||
# shape the bandwidth allowd for a command with trickle: standalone, D:100KB/s, U10KB/s
|
||||
if command -v trickle 1> /dev/null; then
|
||||
alias slow='trickle -s -d 100 -u 10 -t 1'
|
||||
fi
|
||||
|
||||
if command -v xclip 1> /dev/null; then
|
||||
# shortcuts to copy/paste text contents
|
||||
alias xclip-in-txt='xclip -in -rmlastnl -selection clipboard'
|
||||
alias xclip-txt-out='xclip -out -rmlastnl -selection clipboard'
|
||||
# shortcuts to copy/paste other contents
|
||||
alias xclip-in-png='xclip -in -selection clipboard -t image/png'
|
||||
alias xclip-in-jpeg='xclip -in -selection clipboard -t image/jpeg'
|
||||
alias xclip-in-gif='xclip -in -selection clipboard -t image/gif'
|
||||
alias xclip-in-webp='xclip -in -selection clipboard -t image/webp'
|
||||
alias xclip-in-svg='xclip -in -selection clipboard -t image/svg'
|
||||
alias xclip-in-ico='xclip -in -selection clipboard -t image/ico'
|
||||
alias xclip-in-tiff='xclip -in -selection clipboard -t image/tiff'
|
||||
alias xclip-out-png='xclip -out -selection clipboard -t image/png'
|
||||
alias xclip-out-jpeg='xclip -out -selection clipboard -t image/jpeg'
|
||||
alias xclip-out-gif='xclip -out -selection clipboard -t image/gif'
|
||||
alias xclip-out-webp='xclip -out -selection clipboard -t image/webp'
|
||||
alias xclip-out-svg='xclip -out -selection clipboard -t image/svg'
|
||||
alias xclip-out-ico='xclip -out -selection clipboard -t image/ico'
|
||||
alias xclip-out-tiff='xclip -out -selection clipboard -t image/tiff'
|
||||
fi
|
||||
|
||||
# ps alternative on rust
|
||||
if command -v procs 1> /dev/null; then
|
||||
alias procs='procs --insert VmRss --insert VmSwap --insert Threads --insert Priority --insert ElapsedTime --insert State --sortd VmSwap'
|
||||
fi
|
||||
|
||||
# ==============================
|
||||
# New commands or external programs
|
||||
# ==============================
|
||||
|
||||
# custom motd dashboard
|
||||
if [[ -f "/etc/update-motd.d/00-motdfetch" ]]; then
|
||||
alias motd='/etc/update-motd.d/00-motdfetch'
|
||||
fi
|
||||
|
||||
# SSH and ET with MOTD
|
||||
alias sshmotd='ssh -o SetEnv=SSH_MOTD=1'
|
||||
if command -v et 1> /dev/null; then
|
||||
alias etmotd='et --ssh-option SetEnv=SSH_MOTD=1'
|
||||
fi
|
||||
|
||||
# open a new tmux session named ssh_tmux or attach to it
|
||||
if command -v tmux 1> /dev/null; then
|
||||
alias tmuxs='tmux new-session -A -s ssh_tmux && exit'
|
||||
fi
|
||||
|
||||
# vifm: tui file explorer
|
||||
if command -v vifmrun 1> /dev/null && command -v vifm 1> /dev/null; then
|
||||
alias vifm='vifmrun'
|
||||
alias vf='vifmrun'
|
||||
fi
|
||||
|
||||
# dragon for drag&drop function
|
||||
if command -v dragon 1> /dev/null; then
|
||||
alias drag='dragon --and-exit --on-top'
|
||||
alias drop='dragon --and-exit --on-top --target'
|
||||
fi
|
||||
|
||||
# glow: tui/cli markdown pager explorer
|
||||
if command -v glow 1> /dev/null; then
|
||||
alias glw='glow -l -p -w 80 -s dark'
|
||||
fi
|
||||
|
||||
if command -v tidy-viewer 1> /dev/null; then
|
||||
alias tv='tidy-viewer'
|
||||
fi
|
||||
|
||||
# HLEDGER
|
||||
if command -v hledger 1> /dev/null; then
|
||||
export LEDGER_FILE=$HOME/.finance/$(date +"%Y").journal
|
||||
fi
|
||||
|
||||
# get local meteo for 3 days
|
||||
alias meteo='echo -e "┌─────────┐\n│ wttr.in │ ${MYCITY}:\n└─────────┘\n" && curl "wttr.in/$(echo ${MYCITY} | tr " -" "+")?mM2FQ&lang=${LANGUAGE/*:}"'
|
||||
|
||||
# mimic3: tts interactive command, just paste text inside
|
||||
if command -v mimic3 1> /dev/null; then
|
||||
alias mimic3-fr='mimic3 --voice fr_FR/tom_low --play-program paplay --interactive'
|
||||
alias mimic3-en='mimic3 --voice en_US/ljspeech_low --play-program paplay --interactive'
|
||||
alias mimic3-pl='mimic3 --voice pl_PL/m-ailabs_low --play-program paplay --interactive'
|
||||
fi
|
||||
|
||||
# Neomutt, notmuch, mbsync
|
||||
if command -v neomutt 1> /dev/null; then
|
||||
alias ntt='neomutt -f "📫Boite à lettres"'
|
||||
if command -v notmuch 1> /dev/null && command -v mbsync 1> /dev/null; then
|
||||
# Sync all Mailboxes, Notmuch and Afew, then launch Neomutt
|
||||
alias ntt-sync='notmuch new && mbsync mutt && notmuch new && neomutt -f "📫Boite à lettres"'
|
||||
# Sync some Mailboxes, Notmuch and Afew, then launch Neomutt
|
||||
alias ntt-sync-base='notmuch new && mbsync mutt-fast && notmuch new && neomutt -f "📫Boite à lettres"'
|
||||
# Reindex Notmuch and Afew for main, then launch Neomutt
|
||||
alias ntt-index='notmuch new && neomutt -f "📫Boite à lettres"'
|
||||
fi
|
||||
if command -v msmtp-queue 1> /dev/null; then
|
||||
# Flush send mail queue with msmtpq, then launch Neomutt
|
||||
alias ntt-flush='msmtp-queue -r && neomutt -f "📫Boite à lettres"'
|
||||
fi
|
||||
fi
|
||||
|
||||
# Display webcam output with MPV
|
||||
if command -v mpv 1> /dev/null && [[ -c "/dev/video0" ]]; then
|
||||
alias mpv-webcam='mpv av://v4l2:/dev/video0 --profile=low-latency --untimed'
|
||||
if [[ -c "/dev/video2" ]]; then
|
||||
alias mpv-fakecam='mpv av://v4l2:/dev/video2 --profile=low-latency --untimed'
|
||||
fi
|
||||
fi
|
||||
|
||||
# easy downloads with yt-dlp
|
||||
if command -v yt-dlp 1> /dev/null && command -v ffmpeg 1> /dev/null; then
|
||||
alias yt-audio-low='yt-dlp --no-update --socket-timeout 50 --force-ipv4 --limit-rate 1M --downloader wget --paths ${XDG_DOWNLOAD_DIR} --quiet --progress --prefer-free-formats --check-formats --format worstaudio'
|
||||
alias yt-video-medium='yt-dlp --no-update --socket-timeout 50 --force-ipv4 --limit-rate 1M --downloader wget --paths ${XDG_DOWNLOAD_DIR} --quiet --progress --prefer-free-formats --check-formats --format "bestvideo[height<=?360][vbr>100][vbr<500]+worstaudio"'
|
||||
fi
|
||||
|
||||
# to reconnect by tcp:5555 to the adb device currently tethering
|
||||
if command -v adb 1> /dev/null; then
|
||||
alias adb-reconnect='adb disconnect; adb connect $(ip route | egrep "^default" | awk "{print \$3}"):5555'
|
||||
fi
|
715
.bashrc.d/11-functions.bashrc
Normal file
715
.bashrc.d/11-functions.bashrc
Normal file
|
@ -0,0 +1,715 @@
|
|||
#!/usr/bin/env bash
|
||||
# executed by bash(1) for non-login shells.
|
||||
|
||||
# ==============================
|
||||
# FUNCTIONS
|
||||
# ==============================
|
||||
|
||||
# ==============================
|
||||
# System
|
||||
# ==============================
|
||||
|
||||
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
# pass declared functions to sudo, /!\ aliases in the function will not work
|
||||
sudof() {
|
||||
|
||||
Help() {
|
||||
cat <<- HEREDOC
|
||||
|
||||
Pass declared functions as command to sudo bash.
|
||||
Syntax: sudof [-h] <functionName> [<options/arguments>]
|
||||
options:
|
||||
-h Print this Help.
|
||||
|
||||
HEREDOC
|
||||
}
|
||||
while getopts ":h" option; do
|
||||
case $option in
|
||||
h) Help; return 0 ;;
|
||||
\?) echo -e "Unknown option: -$OPTARG \n" >&2; Help; return 1;;
|
||||
: ) echo -e "Missing argument for -$OPTARG \n" >&2; Help; return 1;;
|
||||
* ) echo -e "Unimplemented option: -$option \n" >&2; Help; return 1;;
|
||||
esac
|
||||
done
|
||||
|
||||
local TMPFUNC=$(declare -f "$1")
|
||||
local TMPCMD=${@:1}
|
||||
sudo bash -c "$TMPFUNC; $TMPCMD"
|
||||
}
|
||||
|
||||
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
# Pretty print dependencies from a package with dpkg
|
||||
dpkg-debdep() {
|
||||
dpkg --info "$1" | \
|
||||
awk 'BEGIN{print "Depends:"} \
|
||||
/Depends: / { gsub("Depends: ", ""); \
|
||||
n=split($0,deps,","); \
|
||||
for(i=1;i<=n;i++) print deps[i] \
|
||||
}'
|
||||
}
|
||||
|
||||
# ==============================
|
||||
# Terminal
|
||||
# ==============================
|
||||
|
||||
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
# set of functions for marks/jump, MARKPATH created/exported in 01.env.bashrc
|
||||
mark() { ln -s "$(pwd)" "$MARKPATH/$1"; }
|
||||
unmark() { rm -i "$MARKPATH/$1"; }
|
||||
marks() { ls -l "$MARKPATH" | sed 's/ / /g' | cut -d' ' -f9- | sed 's/ -/\t-/g' && echo; }
|
||||
jump() { cd -P "$MARKPATH/$1" 2>/dev/null || echo "No such mark: $1"; }
|
||||
|
||||
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
# pipe to hl only if you are in a tty and the output is not piped or redirected
|
||||
if command -v hl 1> /dev/null; then
|
||||
hlauto() {
|
||||
if [ -t 1 ]; then
|
||||
hl "$1"
|
||||
else
|
||||
cat -
|
||||
fi
|
||||
}
|
||||
fi
|
||||
|
||||
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
# full page of \n for the clear alias
|
||||
pgdown() {
|
||||
printf '\n%.0s' $(eval echo {1..$(( $(tput lines) - 1 ))})
|
||||
}
|
||||
|
||||
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
# clear teminal and TMUX history and get to the bottom line
|
||||
c() {
|
||||
echo -en "\ec"; pgdown
|
||||
if [[ -n $TMUX_PANE ]]; then
|
||||
tmux clear-history -t "$TMUX_PANE"
|
||||
fi
|
||||
}
|
||||
|
||||
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
# shortcut for tmux to open a new default session with a name or attach if it exist
|
||||
# an alias tmuxs exist too for ssh sessions
|
||||
if command -v tmux 1> /dev/null; then
|
||||
tmuxa() {
|
||||
systemd-run -q --scope --user tmux new-session -A -s default "$@"
|
||||
exit
|
||||
}
|
||||
fi
|
||||
|
||||
# ==============================
|
||||
# Utils
|
||||
# ==============================
|
||||
|
||||
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
# mkdir with sub-dirs and change of pwd
|
||||
md() { mkdir -pv "$1" && cd "$1"; }
|
||||
|
||||
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
# list almost all services units (except user disabled) with state color
|
||||
lservices() {
|
||||
Help() {
|
||||
cat <<- HEREDOC
|
||||
|
||||
List all Systemd services units.
|
||||
Simplified and colorful.
|
||||
|
||||
Syntax: lservices [-h] [-x] [<username>]
|
||||
Output: ServiceName UID STATE DESCRIPTION
|
||||
options:
|
||||
-h Print this Help.
|
||||
-x Copy the list to Clipboard with xclip.
|
||||
-p Disable the pager feature.
|
||||
<username> [root] display --system services,
|
||||
[other] display --user services,
|
||||
[empty] default to current user.
|
||||
|
||||
HEREDOC
|
||||
}
|
||||
|
||||
local OPTIND=0
|
||||
while getopts ":hxp" option; do
|
||||
case $option in
|
||||
h) Help; return 0 ;;
|
||||
x) local _XCLIP=1;;
|
||||
p) local _NOPAGER=1;;
|
||||
\?) echo -e "Unknown option: -$OPTARG \n" >&2; Help; return 1;;
|
||||
: ) echo -e "Missing argument for -$OPTARG \n" >&2; Help; return 1;;
|
||||
* ) echo -e "Unimplemented option: -$option \n" >&2; Help; return 1;;
|
||||
esac
|
||||
done
|
||||
shift $((OPTIND-1))
|
||||
|
||||
if [[ -z $1 ]]; then
|
||||
local _UID=$(id -u)
|
||||
else
|
||||
local _UID=$(id -u $1)
|
||||
fi
|
||||
|
||||
if [[ "$_UID" == "0" ]]; then
|
||||
local _OUT=$(sudo systemctl list-units --system -q --plain --full --no-pager -t service)
|
||||
elif [[ "$_UID" == "$(id -u)" ]]; then
|
||||
local _OUT=$(systemctl list-units --user -q --plain --full --no-pager -t service)
|
||||
else
|
||||
local _OUT=$(sudo machinectl -q shell --uid="$_UID" .host /usr/bin/systemctl list-units --user -q --plain --full --no-pager -t service)
|
||||
fi
|
||||
|
||||
if [[ $_XCLIP == 1 ]]; then
|
||||
echo -e "${_OUT}" | xclip -selection clipboard
|
||||
fi
|
||||
|
||||
local _OUT=$(echo "$_OUT" | awk -v uid=$_UID ' \
|
||||
BEGIN {
|
||||
red = "\033[1;31m"
|
||||
green = "\033[1;32m"
|
||||
yellow = "\033[1;33m"
|
||||
blue = "\033[1;36m"
|
||||
reset = "\033[0m"
|
||||
|
||||
map["running"] = green
|
||||
map["exited"] = yellow
|
||||
map["failed"] = red
|
||||
}
|
||||
match($0,/^(.*)\.service(\s*)loaded\s[a-z]+\s([a-z]+)(\s.*)$/,a) {
|
||||
status = a[3]
|
||||
if ( status in map )
|
||||
$0 = blue a[1] a[2] reset " " uid " " map[status] status reset a[4]
|
||||
else
|
||||
$0 = blue a[1] a[2] reset " " uid " " a[3] a[4]
|
||||
}
|
||||
{ print } '
|
||||
)
|
||||
|
||||
if [[ $_NOPAGER == 1 ]]; then
|
||||
echo -e "${_OUT}"
|
||||
else
|
||||
echo -e "${_OUT}" | less --ignore-case --LONG-PROMPT --mouse --RAW-CONTROL-CHARS --tilde --use-color --quit-if-one-screen
|
||||
fi
|
||||
|
||||
if [[ $_XCLIP == 1 ]]; then
|
||||
echo "List copied in the system clipboard!"
|
||||
fi
|
||||
}
|
||||
|
||||
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
# bat/cat-like with no comments
|
||||
if command -v bat 1> /dev/null; then
|
||||
batl() {
|
||||
bat -pp --color always "$@" \
|
||||
| sed -E -e '1b;/^(\x1B\[[0-9;]+m\s*\x1B\[[0-9;]+m\x1B\[[0-9;]+m)?(\s+)?(\x1B\[[0-9;]+m)?(#|\")/d' \
|
||||
| bat --decorations never --pager "less --ignore-case --status-column --line-numbers --quiet --tilde --use-color --quit-if-one-screen --RAW-CONTROL-CHARS"
|
||||
}
|
||||
fi
|
||||
|
||||
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
# custom alternative to ls that pipe to fzf-tmux or fzf
|
||||
lf() {
|
||||
Help() {
|
||||
cat <<- HEREDOC
|
||||
|
||||
A custom alternative to ls that pipe to fzf-tmux or fzf
|
||||
Accept only the first path submitted (Default=.)
|
||||
|
||||
Syntax: lf [-h] [-a] [-e] [-o] [-t -l level] [<path>]
|
||||
options:
|
||||
-h Print this Help.
|
||||
-a Display hidden files
|
||||
-e Sort by extension
|
||||
-o Sort by oldest
|
||||
-t Tree mode
|
||||
-l num Tree level, default=2
|
||||
|
||||
HEREDOC
|
||||
}
|
||||
|
||||
local _type="list"
|
||||
local _filter="visible"
|
||||
local _by="name"
|
||||
local _lvl=""
|
||||
local _fzf_opt="--preview-window down:5:wrap"
|
||||
|
||||
local OPTIND=0
|
||||
while getopts ":haeotl:" option; do
|
||||
case $option in
|
||||
h) Help; return 0 ;;
|
||||
a) local _all="-a"
|
||||
local _filter="all";;
|
||||
e) local _sort="--sort=extension"
|
||||
local _by="ext" ;;
|
||||
o) local _sort="--sort=oldest"
|
||||
local _by="oldest" ;;
|
||||
t) local _tree="-T"
|
||||
local _type="tree"
|
||||
local _fzf_opt="--keep-right --preview-window down:2:wrap"
|
||||
local _lvl=", with 2 level," ;;
|
||||
l) local _level="-L ${OPTARG}"
|
||||
local _lvl=", with ${OPTARG} level," ;;
|
||||
\?) echo -e "Unknown option: -$OPTARG \n" >&2; Help; return 1;;
|
||||
: ) echo -e "Missing argument for -$OPTARG \n" >&2; Help; return 1;;
|
||||
* ) echo -e "Unimplemented option: -$option \n" >&2; Help; return 1;;
|
||||
esac
|
||||
done
|
||||
shift $((OPTIND-1))
|
||||
|
||||
if [[ -f "/usr/bin/tmux" || -f "/usr/local/bin/tmux" ]]; then
|
||||
local _fzfCmd="fzf-tmux -p 95%,75%"
|
||||
else
|
||||
local _fzfCmd="fzf"
|
||||
fi
|
||||
|
||||
if [ -z "$1" ]; then
|
||||
local _location="$(realpath -sq "$PWD" 2>&1)"
|
||||
elif [ -z "$2" ]; then
|
||||
local _location="$(realpath -sq "$1" 2>&1)"
|
||||
else
|
||||
echo "Error: Invalid number of paths"
|
||||
Help
|
||||
return 0
|
||||
fi
|
||||
|
||||
local _localizer="awk -v loc=\"$_location/\" '{print \"\\\"\" loc \$0 \"\\\"\"}'"
|
||||
local _oneliner="sed -E -e 's/\s->\s.+//g' \
|
||||
| awk '{\$1=\$2=\$3=\$4=\$5=\$6=\$7=\"\"; \$0=\$0; \$1=\$1; print \$0}' \
|
||||
| sed -E -e 's/^[^[:digit:][:alpha:]_.]*\s//g' \
|
||||
| awk -v loc=\"$_location/\" '{print \"\\\"\" loc \$0 \"\\\"\"}' \
|
||||
| xargs -d \"\n\""
|
||||
if [[ "$_type" == "tree" ]]; then
|
||||
local _localizer="awk '{print \"\\\"\" \$0 \"\\\"\"}'"
|
||||
local _oneliner="cat"
|
||||
fi
|
||||
|
||||
exa -bghHl $_all $_sort $_tree $_level --icons --git --color always --group-directories-first --time-style=long-iso "$_location" 2>&1 \
|
||||
| ${_fzfCmd} -p 95%,75% --multi --reverse --ansi --tabstop 2 --header-lines 1 \
|
||||
--prompt "A $_type$_lvl of $_filter elements sorted by $_by in \"$_location\" > " \
|
||||
$_fzf_opt --bind ctrl-a:select-all,ctrl-d:deselect-all,ctrl-t:toggle-all,ctrl-p:toggle-preview \
|
||||
--preview "for line in {+}; do echo \"\$line\"; done \
|
||||
| sed -E -e 's/\s->\s.+//g' \
|
||||
| awk '{\$1=\$2=\$3=\$4=\$5=\$6=\$7=\"\"; \$0=\$0; \$1=\$1; print \$0}' \
|
||||
| sed -E -e 's/^[^[:digit:][:alpha:]_.]*\s//g' \
|
||||
| $_localizer \
|
||||
| xargs -d \"\n\"" \
|
||||
| eval "$_oneliner"
|
||||
}
|
||||
|
||||
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
# find file/symlinks or directories with fd and fzf, use a regex pattern and an optionnal location
|
||||
fdf() {
|
||||
local array=( fd exa fzf bat )
|
||||
for cmd in "${array[@]}"; do
|
||||
if [[ -z $(command -v $cmd) ]]; then
|
||||
echo 'function requirements: $cmd could not be found: sudo apt install fd-find exa fzf bat'
|
||||
return 0
|
||||
fi
|
||||
done
|
||||
|
||||
Help() {
|
||||
cat <<- HEREDOC
|
||||
|
||||
Filesystem search shortcuts with fd, fzf bat and exa
|
||||
|
||||
Syntax: fdf [-h] [-d] [-p] [-e] "<regex_query>" [<location>]
|
||||
options:
|
||||
-h Print this Help.
|
||||
-d search directories only (defaut to files & symlinks)
|
||||
-p preview in fzf (bat for files and exa tree for dirs)
|
||||
-e output results with exa
|
||||
|
||||
HEREDOC
|
||||
}
|
||||
|
||||
local _fdfindType="-tf -tl"
|
||||
if [[ -f "/usr/bin/tmux" || -f "/usr/local/bin/tmux" ]]; then
|
||||
local _fzfCmd="fzf-tmux"
|
||||
else
|
||||
local _fzfCmd="fzf"
|
||||
fi
|
||||
local _previewCdm="bat --style=numbers --color=always --line-range :150 {}"
|
||||
local _xargs="cat"
|
||||
|
||||
local OPTIND=0
|
||||
while getopts ":hdpe" option; do
|
||||
case $option in
|
||||
h) Help; return 0 ;;
|
||||
d) local _fdfindType="-td"
|
||||
local _exaType="-d"
|
||||
local _fzfHeaderType="dir"
|
||||
local _previewCdm="exa -bhlaTL 2 --icons --color always --group-directories-first --no-permissions --time-style=iso {}" ;;
|
||||
p) local _fzfCmd="fzf"
|
||||
local _preview=$_previewCdm ;;
|
||||
e) local _xargs="xargs -r exa -abghHl --icons --color always --group-directories-first --time-style=long-iso" ;;
|
||||
\?) echo -e "Unknown option: -$OPTARG \n" >&2; Help; return 1;;
|
||||
: ) echo -e "Missing argument for -$OPTARG \n" >&2; Help; return 1;;
|
||||
* ) echo -e "Unimplemented option: -$option \n" >&2; Help; return 1;;
|
||||
esac
|
||||
done
|
||||
shift $((OPTIND-1))
|
||||
if [ -z "$1" ]; then
|
||||
echo "Error: fdf needs a <regex_query>"
|
||||
Help
|
||||
return 0
|
||||
fi
|
||||
|
||||
if [ -z "$2" ]; then
|
||||
local _searchPath="$(realpath -sq "$PWD" 2>&1)"
|
||||
else
|
||||
local _searchPath="$(realpath -sq "$2" 2>&1)"
|
||||
fi
|
||||
|
||||
fdfind -0aH $_fdfindType ^$1\$ "$_searchPath" | xargs -r -0 exa $_exaType --colour=always \
|
||||
| $_fzfCmd -m --reverse --ansi --keep-right --bind ctrl-a:select-all,ctrl-d:deselect-all,ctrl-t:toggle-all --header "^$1\$ $_fzfHeaderType in \"$_searchPath\"" --preview "$_preview" | eval "$_xargs"
|
||||
}
|
||||
|
||||
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
# better listing for all tcp/udp sockets
|
||||
ssfull() {
|
||||
if [[ -f "/usr/bin/tmux" || -f "/usr/local/bin/tmux" ]]; then
|
||||
local _fzfCmd="fzf-tmux"
|
||||
else
|
||||
local _fzfCmd="fzf"
|
||||
fi
|
||||
ss -Haptun --cgroup 2>&1 \
|
||||
| awk '{gsub(/cgroup:/,"- - cgroup:",$7);if($7 =="")print $0" - - -";else print $0;}' \
|
||||
| awk '{
|
||||
gsub(/,fd=.+,pid=/,",",$7);gsub(/users:|\(|\)|,fd=[0-9]+/,"",$7);gsub(/,pid=/," ",$7);
|
||||
gsub(/.+\/|cgroup:/,"",$8);
|
||||
gsub(/.+\/|cgroup:/,"",$9);
|
||||
if(match($5, /^.+%[^\]]+:.+$/))localip = gensub(/^(.*[0-9\]*])%.+:[0-9*]{1,5}$/,"\\1","g",$5);else localip = gensub(/^(.*):[0-9*]{1,5}$/,"\\1","g",$5);
|
||||
if(match($5, /^.+%[^\]]+:.+$/))localindex = gensub(/^.+%([^\]]+):.+$/,"\\1","g",$5);else localindex = "-";
|
||||
localport = gensub(/^.*:([^:]*)$/,"\\1","g",$5);
|
||||
if(match($6, /^.+%[^\]]+:.+$/))peerip = gensub(/^(.*[0-9\]*])%.+:[0-9*]{1,5}$/,"\\1","g",$6);else peerip = gensub(/^(.*):[0-9*]{1,5}$/,"\\1","g",$6);
|
||||
if(match($6, /^.+%[^\]]+:.+$/))peerindex = gensub(/^.+%([^\]]+):.+$/,"\\1","g",$6);else peerindex = "-";
|
||||
peerport = gensub(/^.*:([^:]*)$/,"\\1","g",$6);
|
||||
stategroup = "";
|
||||
if(match($2, /^ESTAB$/))stategroup = "1-ESTABL";
|
||||
if(match($2, /^SYN-SENT$/))stategroup = "1-ESTABL";
|
||||
if(match($2, /^SYN-RECV$/))stategroup = "1-ESTABL";
|
||||
if(match($2, /^FIN-WAIT-1$/))stategroup = "2-CLOSIN";
|
||||
if(match($2, /^FIN-WAIT-2$/))stategroup = "2-CLOSIN";
|
||||
if(match($2, /^CLOSE-WAIT$/))stategroup = "2-CLOSIN";
|
||||
if(match($2, /^LAST-ACK$/))stategroup = "2-CLOSIN";
|
||||
if(match($2, /^CLOSING$/))stategroup = "2-CLOSIN";
|
||||
if(match($2, /^TIME-WAIT$/))stategroup = "3-WAITIN";
|
||||
if(match($2, /^LISTEN$/))stategroup = "0-LISTEN";
|
||||
if(match($2, /^UNCONN$/))stategroup = "0-LISTEN";
|
||||
if(stategroup =="")stategroup = "-";
|
||||
if($1 =="tcp" || $1 == "udp")print stategroup,$1,localip,localindex,localport,peerip,peerindex,peerport,$7,$8,$9;
|
||||
}' \
|
||||
| sort -k1,1 -k3,3 -k4,4 -k6,6n \
|
||||
| awk 'BEGIN{print "StateGroup Protocol LocalAddr LocalIndex LocalPort PeerAddr PeerIndex PeerPort Process PID Cgroup"}1' \
|
||||
| column -t \
|
||||
| $_fzfCmd --multi --reverse --ansi --keep-right --tabstop 2 --header-lines 1 --prompt "List of all tcp/udp sockets > " --bind ctrl-a:select-all,ctrl-d:deselect-all,ctrl-t:toggle-all
|
||||
}
|
||||
|
||||
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
# better listing for listening tcp/udp sockets
|
||||
sslisten() {
|
||||
if [[ -f "/usr/bin/tmux" || -f "/usr/local/bin/tmux" ]]; then
|
||||
local _fzfCmd="fzf-tmux"
|
||||
else
|
||||
local _fzfCmd="fzf"
|
||||
fi
|
||||
ss -Hlptun --cgroup 2>&1 \
|
||||
| awk '{gsub(/cgroup:/,"- - cgroup:",$7);if($7 =="")print $0" - - -";else print $0;}' \
|
||||
| awk '{
|
||||
gsub(/,fd=.+,pid=/,",",$7);gsub(/users:|\(|\)|,fd=[0-9]+/,"",$7);gsub(/,pid=/," ",$7);
|
||||
gsub(/.+\/|cgroup:/,"",$8);
|
||||
gsub(/.+\/|cgroup:/,"",$9);
|
||||
if(match($5, /^.+%[^\]]+:.+$/))localip = gensub(/^(.*[0-9\]*])%.+:[0-9*]{1,5}$/,"\\1","g",$5);else localip = gensub(/^(.*):[0-9*]{1,5}$/,"\\1","g",$5);
|
||||
if(match($5, /^.+%[^\]]+:.+$/))localindex = gensub(/^.+%([^\]]+):.+$/,"\\1","g",$5);else localindex = "-";
|
||||
localport = gensub(/^.*:([^:]*)$/,"\\1","g",$5);
|
||||
if(match($6, /^.+%[^\]]+:.+$/))peerip = gensub(/^(.*[0-9\]*])%.+:[0-9*]{1,5}$/,"\\1","g",$6);else peerip = gensub(/^(.*):[0-9*]{1,5}$/,"\\1","g",$6);
|
||||
if(match($6, /^.+%[^\]]+:.+$/))peerindex = gensub(/^.+%([^\]]+):.+$/,"\\1","g",$6);else peerindex = "-";
|
||||
peerport = gensub(/^.*:([^:]*)$/,"\\1","g",$6);
|
||||
stategroup = "";
|
||||
if(match($2, /^LISTEN$/))stategroup = "LISTENING";
|
||||
if(match($2, /^UNCONN$/))stategroup = "LISTENING";
|
||||
if(stategroup =="")stategroup = "-";
|
||||
if($1 =="tcp" || $1 == "udp")print stategroup,$1,localip,localindex,localport,peerip,peerindex,peerport,$7,$8,$9;
|
||||
}' \
|
||||
| sort -k1,1 -k3,3 -k4,4 -k6,6n \
|
||||
| awk 'BEGIN{print "StateGroup Protocol LocalAddr LocalIndex LocalPort PeerAddr PeerIndex PeerPort Process PID Cgroup"}1' \
|
||||
| column -t \
|
||||
| $_fzfCmd --multi --reverse --ansi --keep-right --tabstop 2 --header-lines 1 --prompt "List of LISTENING tcp/udp sockets > " --bind ctrl-a:select-all,ctrl-d:deselect-all,ctrl-t:toggle-all
|
||||
}
|
||||
|
||||
# ==============================
|
||||
# New commands or external programs
|
||||
# ==============================
|
||||
|
||||
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
# set shell working directory after leaving Vifm
|
||||
if command -v vifmrun 1> /dev/null; then
|
||||
vfcd() {
|
||||
local dst="$(command vifmrun --choose-dir - "$@")"
|
||||
if [ -z "$dst" ]; then
|
||||
echo 'Directory picking cancelled/failed'
|
||||
return 1
|
||||
fi
|
||||
cd "$dst"
|
||||
}
|
||||
fi
|
||||
|
||||
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
# simple archive extraction of all kinds, get dep with "sudo apt install tar bzip2 unrar gzip unzip 7zip xz-utils innoextract cabextract"
|
||||
extract() {
|
||||
|
||||
Help() {
|
||||
cat <<- HEREDOC
|
||||
|
||||
Archive extraction simplified.
|
||||
Syntax: extract [-h] <path/file_name>.<zip|rar|bz2|gz|tar|tbz2|tgz|Z|7z|xz|ex|tar.bz2|tar.gz|tar.xz>
|
||||
extract <path/file_name_1.ext> [path/file_name_2.ext] [path/file_name_3.ext]
|
||||
options:
|
||||
-h Print this Help.
|
||||
|
||||
HEREDOC
|
||||
}
|
||||
while getopts ":h" option; do
|
||||
case $option in
|
||||
h) Help; return 0 ;;
|
||||
\?) echo -e "Unknown option: -$OPTARG \n" >&2; Help; return 1;;
|
||||
: ) echo -e "Missing argument for -$OPTARG \n" >&2; Help; return 1;;
|
||||
* ) echo -e "Unimplemented option: -$option \n" >&2; Help; return 1;;
|
||||
esac
|
||||
done
|
||||
|
||||
array=( tar unlzma bunzip2 unrar gunzip unzip uncompress 7z unxz innoextract cabextract )
|
||||
for cmd in "${array[@]}"; do
|
||||
if [[ -z $(command -v "$cmd") ]]; then
|
||||
echo "Requirements: at least $cmd could not be found:"
|
||||
echo "sudo apt install tar bzip2 unrar gzip unzip 7zip xz-utils innoextract cabextract"
|
||||
return 0
|
||||
fi
|
||||
done
|
||||
|
||||
for n in "$@"
|
||||
do
|
||||
if [[ -f "$n" ]] ; then
|
||||
case "${n%,}" in
|
||||
*.tar.bz2|*.tar.gz|*.tar.xz|*.tbz2|*.tgz|*.txz|*.tar)
|
||||
tar xvf "$n" ;;
|
||||
*.lzma) unlzma ./"$n" ;;
|
||||
*.bz2) bunzip2 ./"$n" ;;
|
||||
*.rar) unrar x -ad ./"$n" ;;
|
||||
*.gz) gunzip ./"$n" ;;
|
||||
*.zip) unzip ./"$n" ;;
|
||||
*.z) uncompress ./"$n" ;;
|
||||
*.7z|*.arj|*.cab|*.chm|*.deb|*.dmg|*.iso|*.lzh|*.msi|*.rpm|*.udf|*.wim|*.xar)
|
||||
7z x ./"$n" ;;
|
||||
*.xz) unxz ./"$n" ;;
|
||||
*gog*.exe|*gog*.sh)
|
||||
innoextract -es -c1 -p1 ./"$n" ;;
|
||||
*.exe) cabextract ./"$n" ;;
|
||||
*) echo "extract: '$n' - unknown archive method"; return 1;;
|
||||
esac
|
||||
else
|
||||
echo "'$n' - file does not exist"
|
||||
return 1
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
# Command execution notifier
|
||||
boop() {
|
||||
|
||||
Help() {
|
||||
cat <<- HEREDOC
|
||||
|
||||
Command execution notifier.
|
||||
- In front of a command: notification + sound + NTFY (env: NTFYBOOPSURL, NTFYBOOPSTOKEN)
|
||||
(It send the command name and 1st arg, exec time and exit code)
|
||||
- At the end of a chain: notification + sound
|
||||
|
||||
Syntax: Pre command: boop [-h] [sudo] <some command> | boop <some command>; boop <some command>
|
||||
Post command: <some command>; boop
|
||||
options:
|
||||
-h Print this Help.
|
||||
|
||||
HEREDOC
|
||||
}
|
||||
while getopts ":h" option; do
|
||||
case $option in
|
||||
h) Help; return 0 ;;
|
||||
\?) echo -e "Unknown option: -$OPTARG \n" >&2; Help; return 1;;
|
||||
: ) echo -e "Missing argument for -$OPTARG \n" >&2; Help; return 1;;
|
||||
* ) echo -e "Unimplemented option: -$option \n" >&2; Help; return 1;;
|
||||
esac
|
||||
done
|
||||
|
||||
local STATUS="$?"
|
||||
local ARRAY1=( /usr/bin/time play dunstify )
|
||||
local ARRAY2=( /usr/bin/time curl )
|
||||
for cmd in "${ARRAY2[@]}"; do
|
||||
if [[ -z $(command -v "$cmd") ]]; then
|
||||
echo "boop function requirements: command $cmd could not be found"
|
||||
return 1
|
||||
fi
|
||||
done
|
||||
if [[ -z "$1" ]]; then
|
||||
for cmd in "${ARRAY1[@]}"; do
|
||||
if [[ -z $(command -v "$cmd") ]]; then
|
||||
echo "boop function requirements: command $cmd could not be found"
|
||||
return "$STATUS"
|
||||
fi
|
||||
done
|
||||
if [[ "$STATUS" == '0' ]]; then
|
||||
dunstify -a NTFY -u normal -i dialog-information "Commande terminée avec SUCCÉE ✅ !"
|
||||
play -q -n synth pl G2 pl B2 pl D3 pl B3 pl D4 pl D4 delay 0 .05 .1 .15 .2 .25 remix - fade 0 2 .1 norm -1
|
||||
else
|
||||
dunstify -a NTFY -u critical -i dialog-error "Commande terminée avec une ERREUR ⚠️ !" "Exit code : $STATUS"
|
||||
play -q -n synth 3 sin 960 synth 3 sin fmod 1920 fade l 0 3 2.8 trim 0 1 repeat 2 norm -1
|
||||
fi
|
||||
return "$STATUS"
|
||||
else
|
||||
local FILE=$(mktemp --suffix ".time")
|
||||
boop2ntfy() {
|
||||
local TIME=$(awk 'NR==1{print $1}' "$FILE")
|
||||
local STATUS=$(awk 'NR==1{print $2}' "$FILE")
|
||||
if [[ -z $(awk 'NR==1{print $4}' "$FILE") ]]; then
|
||||
local CMDBEGIN=$(awk 'NR==1{print $3}' "$FILE")
|
||||
else
|
||||
local CMDBEGIN="$(awk 'NR==1{print $3}' "$FILE") $(awk 'NR==1{print $4}' "$FILE")"
|
||||
fi
|
||||
local HOSTNAME=$(hostname)
|
||||
local URL="$NTFYBOOPSURL"
|
||||
local TOKEN="$NTFYBOOPSTOKEN"
|
||||
if [[ "$STATUS" == '0' ]]; then
|
||||
if command -v dunstify 1> /dev/null; then
|
||||
dunstify -a NTFY -u normal -i dialog-information "Commande terminée avec SUCCÉE ✅ !" "Durée : $TIME - Commande : $CMDBEGIN"
|
||||
fi
|
||||
if command -v play 1> /dev/null; then
|
||||
play -q -n synth pl G2 pl B2 pl D3 pl B3 pl D4 pl D4 delay 0 .05 .1 .15 .2 .25 remix - fade 0 2 .1 norm -1
|
||||
fi
|
||||
curl --max-time 25 -s -S -H "Authorization: Bearer ${TOKEN}" -H "X-Title: Hôte : $HOSTNAME" -H tag:tada -d "La commande \"$CMDBEGIN\" s'est terminée avec Succès ! (Durée : $TIME)" "$URL" &> /dev/null
|
||||
else
|
||||
if command -v dunstify 1> /dev/null; then
|
||||
dunstify -a NTFY -u critical -i dialog-error "Commande terminée avec une ERREUR ⚠️ !" "Durée : $TIME - Exit code : $STATUS - Commande : $CMDBEGIN"
|
||||
fi
|
||||
if command -v play 1> /dev/null; then
|
||||
play -q -n synth 3 sin 960 synth 3 sin fmod 1920 fade l 0 3 2.8 trim 0 1 repeat 2 norm -1
|
||||
fi
|
||||
curl --max-time 25 -s -S -H "Authorization: Bearer ${TOKEN}" -H "X-Title: Hôte : $HOSTNAME" -H "X-Priority: 4" -H tag:warning -d "La commande \"$CMDBEGIN\" s'est interrompue avec le code d'Erreur $STATUS ! (Durée : $TIME)" "$URL" &> /dev/null
|
||||
fi
|
||||
}
|
||||
/usr/bin/time -q -f "%E %x %C" -o "$FILE" "$@"; boop2ntfy
|
||||
local EXIT=$(awk 'NR==1{print $2}' "$FILE")
|
||||
rm -f "$FILE"
|
||||
return "$EXIT"
|
||||
fi
|
||||
}
|
||||
|
||||
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
# download a file from Google Drive with continuation : gdrive-dl ID FILENAME
|
||||
gdrivedl() {
|
||||
|
||||
Help() {
|
||||
cat <<- HEREDOC
|
||||
|
||||
Download a file from Google Drive with continuation.
|
||||
Syntax: gdrive-dl [-h] <sharing ID from gdrive uri> <output file name>
|
||||
options:
|
||||
-h Print this Help.
|
||||
|
||||
HEREDOC
|
||||
}
|
||||
while getopts ":h" option; do
|
||||
case $option in
|
||||
h) Help; return 0 ;;
|
||||
\?) echo -e "Unknown option: -$OPTARG \n" >&2; Help; return 1;;
|
||||
: ) echo -e "Missing argument for -$OPTARG \n" >&2; Help; return 1;;
|
||||
* ) echo -e "Unimplemented option: -$option \n" >&2; Help; return 1;;
|
||||
esac
|
||||
done
|
||||
|
||||
local _ID=$1
|
||||
local _FILENAME=$2
|
||||
wget --prefer-family=IPv4 --force-directories --no-check-certificate --no-hsts --continue --load-cookies "/tmp/gdrive-cookies-${_ID}.txt" \
|
||||
"https://docs.google.com/uc?export=download&confirm=$(wget --quiet --save-cookies /tmp/gdrive-cookies-${_ID}.txt \
|
||||
--keep-session-cookies --no-check-certificate 'https://docs.google.com/uc?export=download&id=${_ID}' -O- | \
|
||||
sed -rn 's/.*confirm=([0-9A-Za-z_]+).*/\1\n/p')&id=${_ID}" -O "${XDG_DOWNLOAD_DIR}/$_FILENAME" \
|
||||
&& rm -rf "/tmp/gdrive-cookies-${_ID}.txt"
|
||||
}
|
||||
|
||||
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
# mans - print brief help about a single option or command
|
||||
mans() {
|
||||
Help() {
|
||||
cat <<- HEREDOC 1>&2
|
||||
|
||||
Mans print brief help about a single option or command
|
||||
|
||||
Usage: mans <command> [<option|section>]
|
||||
Example:
|
||||
mans bash getopts Documentation for bash getopts
|
||||
mans ssh -v Documentation for ssh -v flag
|
||||
mans select SYNOPSIS for select(2)
|
||||
mans 'open(2)' SYNOPSIS for open(2)
|
||||
|
||||
HEREDOC
|
||||
}
|
||||
|
||||
if test $# -lt 1; then
|
||||
Help
|
||||
return 0
|
||||
fi
|
||||
|
||||
manpage="$1"
|
||||
# show the SYNOPSIS section if no section or option was given
|
||||
option="${2:-SYNOPSIS}"
|
||||
|
||||
# handle manpage(number)
|
||||
case $manpage in *\(*\))
|
||||
page=${manpage%\(*\)}
|
||||
section=${manpage#"$page"}
|
||||
section=${section#\(}
|
||||
section=${section%\)}
|
||||
manpage="$page"
|
||||
;;
|
||||
esac
|
||||
|
||||
man ${section:+-s $section} "$manpage" | perl -n -e \
|
||||
'BEGIN {
|
||||
$option = "'"$option"'";
|
||||
$inside_option = 0;
|
||||
}
|
||||
if (!$inside_option) {
|
||||
if (/^(\s*)\Q$option\E\b/p) {
|
||||
# start of this option
|
||||
$option_indentation = $1;
|
||||
$inside_option = 1;
|
||||
$saw_blank_line = 0;
|
||||
print;
|
||||
}
|
||||
} else {
|
||||
if (/^$/) {
|
||||
$saw_blank_line = 1;
|
||||
print;
|
||||
} elsif (/^\Q$option_indentation\E\S/ and $saw_blank_line) {
|
||||
# item at same indentation => start of next option
|
||||
$inside_option = 0;
|
||||
} elsif (/^\S/) {
|
||||
# new heading => start of next section
|
||||
$inside_option = 0;
|
||||
} else {
|
||||
print;
|
||||
}
|
||||
}' | { if command -v hl 1> /dev/null; then hlauto --man; else cat -; fi }
|
||||
}
|
||||
|
||||
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
# br - This function starts broot and executes the command
|
||||
if command -v br 1> /dev/null; then
|
||||
br() {
|
||||
local cmd cmd_file code
|
||||
cmd_file=$(mktemp)
|
||||
if broot --outcmd "$cmd_file" "$@"; then
|
||||
cmd=$(<"$cmd_file")
|
||||
command rm -f "$cmd_file"
|
||||
eval "$cmd"
|
||||
else
|
||||
code=$?
|
||||
command rm -f "$cmd_file"
|
||||
return "$code"
|
||||
fi
|
||||
}
|
||||
fi
|
68
.bashrc.d/12-bindings.bashrc
Normal file
68
.bashrc.d/12-bindings.bashrc
Normal file
|
@ -0,0 +1,68 @@
|
|||
#!/usr/bin/env bash
|
||||
# executed by bash(1) for non-login shells.
|
||||
|
||||
# ==============================
|
||||
# BINDINGS
|
||||
# ==============================
|
||||
|
||||
# ==============================
|
||||
# FZF-EMOJI-WIDGET
|
||||
# ==============================
|
||||
|
||||
# custom emojis selector with fzf, inspired by fzf shell bindings
|
||||
# Require bash > v4; I did not copy other shells solutions from fzf shell bindings
|
||||
# => pip --user install emoji-fzf
|
||||
# => sudo apt install fzf
|
||||
if [[ -f "$HOME/.local/bin/emoji-fzf" ]]; then
|
||||
fzf-emoji-widget() {
|
||||
Help() {
|
||||
echo "FZF widget to insert or replace some emojis."
|
||||
echo "Use it with bash>4 and 'bind -x'"
|
||||
echo "Default: insert emojis in place."
|
||||
echo
|
||||
echo "Syntax: [-h] [-i]"
|
||||
echo "options:"
|
||||
echo "-h Print this Help."
|
||||
echo "-i Replace the word before cursor, using it as a query"
|
||||
echo
|
||||
# READLINE(command line string) and READLINE_POINT(cursor position)
|
||||
# are generated by bind.
|
||||
}
|
||||
local OPTIND=0
|
||||
while getopts ":hi" option; do
|
||||
case $option in
|
||||
h) Help
|
||||
return 0 ;;
|
||||
i) local _REPLACE=1
|
||||
local _QUERYLINE=${READLINE_LINE:0:READLINE_POINT}
|
||||
local _QUERYLINE_POINT=${#_QUERYLINE}
|
||||
local _QUERY="${_QUERYLINE/* /}"
|
||||
local _QUERYLINE_START=$(( _QUERYLINE_POINT - "${#_QUERY}" )) ;;
|
||||
\?) echo "Error: Invalid option: -$OPTARG"
|
||||
Help
|
||||
return 0 ;;
|
||||
esac
|
||||
done
|
||||
shift $((OPTIND-1))
|
||||
|
||||
local selected=$(emoji-fzf preview --prepend | fzf-tmux -p 85% --multi --reverse --no-hscroll --header "Select multiple emojis with Tab and validate with Enter." --query "$_QUERY" | cut -d " " -f 2 | emoji-fzf get | xargs -d "\n")
|
||||
|
||||
if [[ $_REPLACE == 1 ]]; then
|
||||
READLINE_LINE="${READLINE_LINE:0:$_QUERYLINE_START}$selected${READLINE_LINE:READLINE_POINT}"
|
||||
READLINE_POINT=$(( _QUERYLINE_START + "${#selected}" ))
|
||||
else
|
||||
READLINE_LINE="${READLINE_LINE:0:$READLINE_POINT}$selected${READLINE_LINE:READLINE_POINT}"
|
||||
READLINE_POINT=$(( READLINE_POINT + "${#selected}" ))
|
||||
fi
|
||||
}
|
||||
|
||||
# ALT-e - Paste emojis from a list into the command line
|
||||
bind -m emacs-standard -x '"\ee": fzf-emoji-widget'
|
||||
bind -m vi-command -x '"\ee": fzf-emoji-widget'
|
||||
bind -m vi-insert -x '"\ee": fzf-emoji-widget'
|
||||
|
||||
# ALT-i - Replace the word before cursor with emojis from a list
|
||||
bind -m emacs-standard -x '"\ei": fzf-emoji-widget -i'
|
||||
bind -m vi-command -x '"\ei": fzf-emoji-widget -i'
|
||||
bind -m vi-insert -x '"\ei": fzf-emoji-widget -i'
|
||||
fi
|
243
.bashrc.d/20-prompt-conf.bashrc
Normal file
243
.bashrc.d/20-prompt-conf.bashrc
Normal file
|
@ -0,0 +1,243 @@
|
|||
#!/usr/bin/env bash
|
||||
# executed by bash(1) for non-login shells.
|
||||
|
||||
####################################
|
||||
# LIQUID PROMPT CONFIGURATION FILE #
|
||||
####################################
|
||||
|
||||
# This example config file does not contain all possible config options, nor
|
||||
# does it have detailed option descriptions. See the documentation for that:
|
||||
# https://liquidprompt.readthedocs.io/en/stable/config.html
|
||||
|
||||
#############
|
||||
# BEHAVIOUR #
|
||||
#############
|
||||
|
||||
# Display the battery level in more urgent color when the level is below this threshold.
|
||||
# Recommended value is 75
|
||||
LP_BATTERY_THRESHOLD=75
|
||||
|
||||
# Display the load average over the past minute when above this threshold.
|
||||
# This value is scaled per CPU, so on a quad-core machine, the load average
|
||||
# would need to be 2.40 or greater to be displayed.
|
||||
# Recommended value is 0.60
|
||||
LP_LOAD_THRESHOLD=0.80
|
||||
|
||||
# Display the temperature when the temperate is above this threshold (in
|
||||
# degrees Celsius).
|
||||
# Recommended value is 60
|
||||
LP_TEMP_THRESHOLD=60
|
||||
|
||||
# Use the shorten path feature if the path is too long to fit in the prompt
|
||||
# line.
|
||||
# Recommended value is 1
|
||||
LP_ENABLE_SHORTEN_PATH=1
|
||||
|
||||
# The maximum percentage of the screen width used to display the path before
|
||||
# removing the center portion of the path and replacing with '...'.
|
||||
# Recommended value is 35
|
||||
LP_PATH_LENGTH=35
|
||||
|
||||
# The number of directories (including '/') to keep at the beginning of a
|
||||
# shortened path.
|
||||
# Recommended value is 2
|
||||
LP_PATH_KEEP=3
|
||||
|
||||
# Determine if the hostname should always be displayed, even if not connecting
|
||||
# through network.
|
||||
# Defaults to 0 (do not display hostname when locally connected)
|
||||
# set to 1 if you want to always see the hostname
|
||||
# set to -1 if you want to never see the hostname
|
||||
LP_HOSTNAME_ALWAYS=0
|
||||
|
||||
# When to display the user name:
|
||||
# 1: always display the user name
|
||||
# 0: hide the logged user (always display different users)
|
||||
# -1: never display the user name
|
||||
# Default value is 1
|
||||
LP_USER_ALWAYS=1
|
||||
|
||||
# Display the actual values of load/batteries along with their
|
||||
# corresponding marks. Set to 0 to only print the colored marks.
|
||||
# Defaults to 1 (display percentages)
|
||||
LP_PERCENTS_ALWAYS=1
|
||||
|
||||
# Display a user-defined set of environment variables.
|
||||
# May show if the variables are unset, set, or their actual content
|
||||
# (see below to configure which variables to watch).
|
||||
LP_ENABLE_ENV_VARS=1
|
||||
|
||||
# The set of environment variables that the user wants to watch.
|
||||
# Items should be a string with three space-separated elements
|
||||
# of the form `"<name> <set>[ <unset>]"`
|
||||
# The string used when the variable is set may contain the `%s` mark,
|
||||
# which is replaced by the actual content of the variable.
|
||||
LP_ENV_VARS=(
|
||||
# # Display "V" if VERBOSE is set, nothing if it's unset.
|
||||
# "VERBOSE V"
|
||||
# # Display the name of the desktop session, if set, T if unset.
|
||||
# "DESKTOP_SESSION %s T"
|
||||
# # Display "ed:" followed the name of the default editor, nothing if unset.
|
||||
# "EDITOR ed:%s"
|
||||
)
|
||||
|
||||
# Use the permissions feature and display a red ':' before the prompt to show
|
||||
# when you don't have write permission to the current directory.
|
||||
# Recommended value is 1
|
||||
LP_ENABLE_PERM=1
|
||||
|
||||
# Enable the proxy detection feature.
|
||||
# Recommended value is 1
|
||||
LP_ENABLE_PROXY=0
|
||||
|
||||
# Enable the jobs feature.
|
||||
# Recommended value is 1
|
||||
LP_ENABLE_JOBS=1
|
||||
|
||||
# Enable the detached sessions feature.
|
||||
# Default value is 1
|
||||
LP_ENABLE_DETACHED_SESSIONS=0
|
||||
|
||||
# Enable the load feature.
|
||||
# Recommended value is 1
|
||||
LP_ENABLE_LOAD=1
|
||||
|
||||
# Enable the battery feature.
|
||||
# Recommended value is 1
|
||||
LP_ENABLE_BATT=0
|
||||
|
||||
# Enable the 'sudo credentials' feature.
|
||||
# Be warned that this may pollute the syslog if you don't have sudo
|
||||
# credentials, and the sysadmin might hate you.
|
||||
LP_ENABLE_SUDO=0
|
||||
|
||||
# Enable the directory stack support.
|
||||
LP_ENABLE_DIRSTACK=0
|
||||
|
||||
# Enable the VCS features with the root account.
|
||||
# Recommended value is 0
|
||||
LP_ENABLE_VCS_ROOT=0
|
||||
|
||||
# Enable the Git special features.
|
||||
# Recommended value is 1
|
||||
LP_ENABLE_GIT=0
|
||||
|
||||
# Enable the Subversion special features.
|
||||
# Recommended value is 1
|
||||
LP_ENABLE_SVN=0
|
||||
|
||||
# Enable the Mercurial special features.
|
||||
# Recommended value is 1
|
||||
LP_ENABLE_HG=0
|
||||
|
||||
# Enable the Fossil special features.
|
||||
# Recommended value is 1
|
||||
LP_ENABLE_FOSSIL=0
|
||||
|
||||
# Enable the Bazaar special features.
|
||||
# Recommended value is 1
|
||||
LP_ENABLE_BZR=0
|
||||
|
||||
# Show time of when the current prompt was displayed.
|
||||
LP_ENABLE_TIME=1
|
||||
|
||||
# Show runtime of the previous command if over LP_RUNTIME_THRESHOLD
|
||||
# Recommended value is 0
|
||||
LP_ENABLE_RUNTIME=1
|
||||
|
||||
# Minimal runtime (in seconds) before the runtime will be displayed
|
||||
# Recommended value is 2
|
||||
LP_RUNTIME_THRESHOLD=3
|
||||
|
||||
# Ring the terminal bell if the runtime of the previous command exceeded
|
||||
# LP_RUNTIME_BELL_THRESHOLD
|
||||
# Recommended value is 0
|
||||
LP_ENABLE_RUNTIME_BELL=0
|
||||
|
||||
# Minimal runtime (in seconds) before the terminal bell will be rung.
|
||||
# Recommended value is 10
|
||||
LP_RUNTIME_BELL_THRESHOLD=10
|
||||
|
||||
# Display the virtualenv that is currently activated, if any
|
||||
# Recommended value is 1
|
||||
LP_ENABLE_VIRTUALENV=1
|
||||
|
||||
# Display the ruby virtual env that is currently activated, if any
|
||||
# Recommended value is 1
|
||||
LP_ENABLE_RUBY_VENV=1
|
||||
|
||||
# If using RVM, personalize the rvm-prompt.
|
||||
# see http://rvm.io/workflow/prompt for details.
|
||||
# Warning, this variable must be a shell array.
|
||||
LP_RUBY_RVM_PROMPT_OPTIONS=(i v g s)
|
||||
|
||||
# Display the terraform workspace that is currently activated, if any
|
||||
# Recommended value is 0
|
||||
LP_ENABLE_TERRAFORM=0
|
||||
|
||||
# Display the enabled software collections, if any
|
||||
# Recommended value is 1
|
||||
LP_ENABLE_SCLS=0
|
||||
|
||||
# Show current Kubernetes kubectl context
|
||||
LP_ENABLE_KUBECONTEXT=0
|
||||
|
||||
# Delimiter to shorten kubectl context by removing a suffix.
|
||||
# E.g. when your context names are dev-cluster and test-cluster, set to "-"
|
||||
# in order to output "dev" and "test" in prompt.
|
||||
LP_DELIMITER_KUBECONTEXT_SUFFIX=
|
||||
|
||||
# Delimiter to shorten kubectl context by removing a prefix.
|
||||
# E.g. when your context names are like
|
||||
# arn:aws:eks:$REGION:$ACCOUNT_ID:cluster/$CLUSTER_NAME, set to "/"
|
||||
# in order to output "$CLUSTER_NAME" in prompt.
|
||||
LP_DELIMITER_KUBECONTEXT_PREFIX=
|
||||
|
||||
# Display the current active AWS_PROFILE, if any
|
||||
# Recommended value is 1
|
||||
LP_ENABLE_AWS_PROFILE=0
|
||||
|
||||
# Show highest system temperature
|
||||
LP_ENABLE_TEMP=1
|
||||
|
||||
# When showing the time, use an analog clock instead of numeric values.
|
||||
# Recommended value is 0
|
||||
LP_TIME_ANALOG=0
|
||||
|
||||
# Use the prompt as the title of the terminal window
|
||||
# Recommended value is 0
|
||||
LP_ENABLE_TITLE=0
|
||||
|
||||
# Enable Title for screen, byobu, and tmux
|
||||
LP_ENABLE_SCREEN_TITLE=0
|
||||
|
||||
# Use different colors for the different hosts you SSH to
|
||||
LP_ENABLE_SSH_COLORS=0
|
||||
|
||||
# Show the error code of the last command if it was not 0
|
||||
LP_ENABLE_ERROR=1
|
||||
|
||||
# Show the (guessed) error meaning after the error code.
|
||||
LP_ENABLE_ERROR_MEANING=0
|
||||
|
||||
# Extends the list of guessed error meanings (may produce wrong meanings).
|
||||
LP_ENABLE_ERROR_MEANING_EXTENDED=0
|
||||
|
||||
# Specify an array of absolute paths in which all vcs will be disabled.
|
||||
# Ex: ("/root" "/home/me/large-remove-svn-repo")
|
||||
LP_DISABLED_VCS_PATHS=()
|
||||
|
||||
# Use a local liquidpromptrc if it exists.
|
||||
# Can be helpful if you sync your primary config across machines, or if
|
||||
# there's a system-wide config at /etc/liquidpromptrc from which you'd
|
||||
# like to make only minor deviations.
|
||||
#LOCAL_RCFILE=$HOME/.liquidpromptrc.local
|
||||
#[ -f "$LOCAL_RCFILE" ] && source "$LOCAL_RCFILE"
|
||||
|
||||
# Show the value of $SHLVL, which is the number of nested shells. For example,
|
||||
# if one runs bash inside their shell, it will open a new shell inside their current shell,
|
||||
# and this will display “2”.
|
||||
LP_ENABLE_SHLVL=0
|
||||
|
||||
|
||||
# vim: set et sts=4 sw=4 tw=120 ft=sh:
|
148
.bashrc.d/21-prompt-theme.bashrc
Normal file
148
.bashrc.d/21-prompt-theme.bashrc
Normal file
|
@ -0,0 +1,148 @@
|
|||
#!/usr/bin/env bash
|
||||
# executed by bash(1) for non-login shells.
|
||||
|
||||
####################################
|
||||
# LIQUID PROMPT DEFAULT THEME FILE #
|
||||
####################################
|
||||
|
||||
# Special characters
|
||||
# Be sure to use characters that exists in the font you use. You can use several
|
||||
# characters at once.
|
||||
# Below is an example of how to fallback to ASCII if the term is not Unicode-capable.
|
||||
# Defaults to UTF-8 characters.
|
||||
if [[ "$(locale -k LC_CTYPE | sed -n 's/^charmap="\(.*\)"/\1/p')" == *"UTF-8"* ]]; then
|
||||
# If charset is UTF-8.
|
||||
LP_MARK_BATTERY="⌁" # in front of the battery charge
|
||||
LP_MARK_ADAPTER="⏚" # displayed when plugged
|
||||
LP_MARK_LOAD="⌂" # in front of the load
|
||||
LP_MARK_TEMP="θ" # in front of the temp
|
||||
LP_MARK_PROXY="↥" # indicate a proxy in use
|
||||
LP_MARK_HG="☿" # prompt mark in hg repositories
|
||||
LP_MARK_SVN="‡" # prompt mark in svn repositories
|
||||
LP_MARK_GIT="±" # prompt mark in git repositories
|
||||
LP_MARK_FOSSIL="⌘" # prompt mark in fossil repositories
|
||||
LP_MARK_DISABLED="⌀" # prompt mark in directory with disabled VCS info
|
||||
LP_MARK_UNTRACKED="*" # if git has untracked files
|
||||
LP_MARK_STASH="+" # if git has stashs
|
||||
LP_MARK_SHORTEN_PATH=" … " # prompt mark in shortened paths
|
||||
LP_MARK_PERM=": " # separator between host and path
|
||||
LP_MARK_KUBECONTEXT="⎈" # Kubernetes context
|
||||
LP_MARK_SHLVL="└" # number of nested shells
|
||||
else
|
||||
# If charset is anything else, fallback to ASCII chars
|
||||
LP_MARK_BATTERY="b"
|
||||
LP_MARK_ADAPTER="p"
|
||||
LP_MARK_LOAD="c"
|
||||
LP_MARK_TEMP="T"
|
||||
LP_MARK_PROXY="^"
|
||||
LP_MARK_HG="m"
|
||||
LP_MARK_SVN="="
|
||||
LP_MARK_GIT="+"
|
||||
LP_MARK_FOSSIL="f"
|
||||
LP_MARK_DISABLED="!"
|
||||
LP_MARK_UNTRACKED="*"
|
||||
LP_MARK_STASH="+"
|
||||
LP_MARK_SHORTEN_PATH=" ... "
|
||||
LP_MARK_PERM=": "
|
||||
LP_MARK_KUBECONTEXT="k8s:"
|
||||
fi
|
||||
|
||||
LP_MARK_BRACKET_OPEN="[" # open bracket
|
||||
LP_MARK_BRACKET_CLOSE="]" # close bracket
|
||||
#LP_MARK_PREFIX=$'\n' # newline prompt mark prefix
|
||||
LP_MARK_PREFIX=" " # prompt mark prefix
|
||||
LP_PS1_PREFIX=""
|
||||
LP_PS1_POSTFIX=""
|
||||
|
||||
# Colors
|
||||
# Available colors are:
|
||||
# BOLD, BLACK, BOLD_GRAY, WHITE, BOLD_WHITE,
|
||||
# RED, BOLD_RED, WARN_RED, CRIT_RED, DANGER_RED,
|
||||
# GREEN, BOLD_GREEN, YELLOW, BOLD_YELLOW, BLUE,
|
||||
# BOLD_BLUE, PURPLE, PINK, CYAN, BOLD_CYAN
|
||||
# Set to a null string "" if you do not want color.
|
||||
|
||||
# Current working directory
|
||||
LP_COLOR_PATH="$BOLD" # as normal user
|
||||
LP_COLOR_PATH_ROOT="$BOLD_YELLOW" # as root
|
||||
|
||||
# Color of the proxy mark
|
||||
LP_COLOR_PROXY="$BOLD_BLUE"
|
||||
|
||||
# Jobs count
|
||||
LP_COLOR_JOB_D="$YELLOW" # Detached (aka screen sessions)
|
||||
LP_COLOR_JOB_R="$BOLD_YELLOW" # Running (xterm &)
|
||||
LP_COLOR_JOB_Z="$BOLD_YELLOW" # Sleeping (Ctrl-Z)
|
||||
|
||||
# Last error code
|
||||
LP_COLOR_ERR="$PURPLE"
|
||||
|
||||
# Prompt mark
|
||||
LP_COLOR_MARK="$BOLD" # as user
|
||||
LP_COLOR_MARK_ROOT="$BOLD_RED" # as root
|
||||
LP_COLOR_MARK_SUDO="$BOLD_RED" # when sudo credentials are cached
|
||||
|
||||
# Current user
|
||||
LP_COLOR_USER_LOGGED="" # user who logged in
|
||||
LP_COLOR_USER_ALT="$BOLD" # user but not the one who logged in
|
||||
LP_COLOR_USER_ROOT="$BOLD_YELLOW" # root
|
||||
|
||||
# Hostname
|
||||
LP_COLOR_HOST="" # local host
|
||||
LP_COLOR_SSH="$BLUE" # connected via SSH
|
||||
LP_COLOR_SU="$BOLD_YELLOW" # connected remotely but in new environment through su/sudo
|
||||
LP_COLOR_TELNET="$WARN_RED" # connected via telnet
|
||||
LP_COLOR_X11_ON="$GREEN" # connected with X11 support
|
||||
LP_COLOR_X11_OFF="$YELLOW" # connected without X11 support
|
||||
|
||||
# Separation mark (aka permission in the working dir)
|
||||
LP_COLOR_WRITE="$GREEN" # have write permission
|
||||
LP_COLOR_NOWRITE="$RED" # do not have write permission
|
||||
|
||||
# VCS
|
||||
LP_COLOR_UP="$GREEN" # repository is up to date / a push have been made
|
||||
LP_COLOR_COMMITS="$YELLOW" # some commits have not been pushed
|
||||
LP_COLOR_COMMITS_BEHIND="$BOLD_RED" # some commits have not been pushed
|
||||
LP_COLOR_CHANGES="$RED" # there is some changes to commit
|
||||
LP_COLOR_DIFF="$PURPLE" # number of lines impacted by current changes
|
||||
|
||||
# Battery
|
||||
LP_COLOR_CHARGING_ABOVE="$GREEN" # charging and above threshold
|
||||
LP_COLOR_CHARGING_UNDER="$YELLOW" # charging but under threshold
|
||||
LP_COLOR_DISCHARGING_ABOVE="$YELLOW" # discharging but above threshold
|
||||
LP_COLOR_DISCHARGING_UNDER="$RED" # discharging and under threshold
|
||||
|
||||
# Time
|
||||
LP_COLOR_TIME="$BLUE"
|
||||
|
||||
# Brackets inside screen/tmux
|
||||
LP_COLOR_IN_MULTIPLEXER="$BOLD_BLUE"
|
||||
|
||||
# Virtual environment
|
||||
LP_COLOR_VIRTUALENV="$CYAN"
|
||||
|
||||
# Kubernetes
|
||||
LP_COLOR_KUBECONTEXT="$CYAN"
|
||||
|
||||
# Terraform
|
||||
LP_COLOR_TERRAFORM="$PINK"
|
||||
|
||||
# Runtime
|
||||
LP_COLOR_RUNTIME="$YELLOW"
|
||||
|
||||
# Color map (for battery and load levels, and temperature)
|
||||
# Range from 0 (nothing special) to 9 (alert)
|
||||
LP_COLORMAP=(
|
||||
""
|
||||
"$GREEN"
|
||||
"$BOLD_GREEN"
|
||||
"$YELLOW"
|
||||
"$BOLD_YELLOW"
|
||||
"$RED"
|
||||
"$BOLD_RED"
|
||||
"$WARN_RED"
|
||||
"$CRIT_RED"
|
||||
"$DANGER_RED"
|
||||
)
|
||||
|
||||
# vim: set et sts=4 sw=4 tw=120 ft=sh:
|
4627
.bashrc.d/22-prompt.bashrc
Normal file
4627
.bashrc.d/22-prompt.bashrc
Normal file
File diff suppressed because it is too large
Load diff
20
.bashrc.d/99-autostart.bashrc
Normal file
20
.bashrc.d/99-autostart.bashrc
Normal file
|
@ -0,0 +1,20 @@
|
|||
#!/usr/bin/env bash
|
||||
# ~/.bashrc: executed by bash(1) for non-login shells.
|
||||
|
||||
# ==============================
|
||||
# AUTOSTART
|
||||
# ==============================
|
||||
|
||||
# run tmux if TMUX variable is null
|
||||
if [[ "${TERM-}" != tmux* ]] && [[ -z "${TMUX}" ]] && [[ -z "${SSH_CONNECTION}" ]]; then
|
||||
tmuxa
|
||||
elif [[ -z "${TMUX}" ]] && [[ -n "${SSH_CONNECTION}" ]]; then
|
||||
tmuxs
|
||||
fi
|
||||
# run MOTD at login only in an ssh session
|
||||
if [[ -n "${TMUX}" ]] && [[ -n "${SSH_CONNECTION}" ]] && [[ "${SSH_MOTD-}" == 1 ]] && [[ -f "/etc/update-motd.d/00-motdfetch" ]]; then
|
||||
motd
|
||||
else
|
||||
# use function pgdown to get the prompt to terminal window bottom
|
||||
pgdown
|
||||
fi
|
60
.profile
Normal file
60
.profile
Normal file
|
@ -0,0 +1,60 @@
|
|||
# ~/.profile: executed by the command interpreter for login shells.
|
||||
# This file is not read by bash(1), if ~/.bash_profile or ~/.bash_login
|
||||
# exists.
|
||||
|
||||
# if running with bash
|
||||
if [ -n "$BASH_VERSION" ]; then
|
||||
# include .bashrc if it exists
|
||||
if [ -f "$HOME/.bashrc" ]; then
|
||||
. "$HOME/.bashrc"
|
||||
fi
|
||||
else
|
||||
# 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
|
||||
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
|
||||
|
||||
# ==============================
|
||||
# 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
|
||||
|
||||
# opt-out for .NET telemetry
|
||||
if command -v dontnet 1> /dev/null; then
|
||||
export DOTNET_CLI_TELEMETRY_OPTOUT=1
|
||||
fi
|
||||
fi
|
Loading…
Reference in a new issue