update bash

This commit is contained in:
masterzu 2024-10-30 19:05:35 +01:00
parent 9f0eca64ef
commit e964a95093
Signed by untrusted user who does not match committer: pcao
GPG Key ID: B57DBE40C72FBCF4
4 changed files with 129 additions and 51 deletions

View File

@ -5,8 +5,8 @@ alias l='ls -lh'
alias la='ls -Alh'
alias lt='ls -lrt'
alias d='ls -al | egrep ^d'
alias dl='ls -al | grep -E "^[d|l]"'
alias ll='ls -al | grep -E ^l'
alias dl='ls -al | egrep "^[d|l]"'
alias ll='ls -alh'
alias h=history
alias td='todo -c --force-colour --filter -done,+children | less -r'
alias tdall='todo --force-colour -A|less -r'
@ -68,14 +68,14 @@ alias vic='vim ~/.irssi/config'
# mutt
alias cm='cd ~/.mutt'
alias vm='vim ~/.mutt/muttrc'
alias vma='vim ~/.mutt/muttrc-alias'
alias ou='offlineimap -a upmc'
alias og='offlineimap -a gmail'
alias vma='vim ~/.mutt/alias'
# w3m
alias cw='cd ~/.w3m'
alias vw='vim ~/.w3m/config'
alias wb='w3m -B'
# fzf
alias vf='vim $(fzf --preview="head -$LINES {}")'
alias of='xdg-open "$(fzf --preview="head -$LINES {}")"'
#newsboat
alias nb=newsboat
@ -144,13 +144,6 @@ alias vss='vi ~/.config/starship.toml'
alias gt="go test | _gotestcolored"
alias gtv="go test -v | _gotestcolored"
# go buffalo
# alias bt='buffalo test | _gotestcolored'
# alias btv='buffalo test -v | _gotestcolored | less'
# force no caching in test with -count=1
alias bt="go test -p 1 -tags test subscribe subscribe/actions subscribe/grifts subscribe/mailers"
alias btv='bt -v | _gotestcolored | less '
alias pm='sudo pacman'
# end .bash_aliases

View File

@ -16,7 +16,10 @@
RED="\[\033[0;31m\]"
YELLOW="\[\033[0;33m\]"
GREEN="\[\033[0;32m\]"
YELLOW="\[\033[0;33m\]"
BLUE="\[\033[0;34m\]"
MAGENTA="\[\033[0;35m\]"
CYAN="\[\033[0;36m\]"
LIGHT_RED="\[\033[1;31m\]"
LIGHT_GREEN="\[\033[1;32m\]"
LIGHT_YELLOW="\[\033[1;33m\]"
@ -89,7 +92,7 @@ function prompt_func() {
test "`id -ng`" != "`id -nu`" && psnewgrp="${LIGHT_GREEN}(`id -ng`)"
# [user$host]
prompt="${prompt}${COLOR_NONE}[${YELLOW}\u${psnewgrp}${COLOR_NONE}@${WHITE}\h${COLOR_NONE}]"
prompt="${prompt}${COLOR_NONE}[${YELLOW}\u${COLOR_NONE}@${WHITE}\h${COLOR_NONE}]"
# python virtualenv
test -n "$VIRTUAL_ENV" && prompt="${prompt} (env:${BLUE}$(basename $VIRTUAL_ENV)${COLOR_NONE})"
@ -115,6 +118,13 @@ function prompt_func() {
# prompt="${prompt} \w"
prompt="${prompt} $(short_path "$PWD")"
# if test $previous_return_value -eq 0
# then
# PS1="${prompt} ${GREEN}\$${COLOR_NONE} "
# else
# PS1="${prompt} ${RED}(err=${previous_return_value}) \$${COLOR_NONE} "
# fi
# test right align FIXME
# PS1=$(printf "%${COLUMNS}s \r%s" "${prompt}" "${GREEN}\$${COLOR_NONE} ")

110
.bashrc
View File

@ -26,12 +26,6 @@ shopt -s checkwinsize
## autocd
shopt -s autocd
# make less more friendly for non-text input files, see lesspipe(1)
[ -x /usr/bin/lesspipe ] && eval "$(lesspipe)"
# LESS options
export LESS="-FRX"
# very basic prompt -- more in .bash_prompt
PROMPT_COMMAND='PS1="[\u@\h] -- \w "; echo -ne "\033]0;${USER}@${HOSTNAME}: ${PWD/$HOME/~}\007"'
@ -44,6 +38,8 @@ export BROWSER=w3m
# ... and vim is the Best
export EDITOR=vim
export PAGER=less
# very min bash aliases
alias ls='ls -F --color'
alias l='ls -l'
@ -55,6 +51,7 @@ alias wa='ssh warhol'
#
test -f ~/.bash_aliases && source ~/.bash_aliases
test -f ~/.bash_prompt && source ~/.bash_prompt
eval $(dircolors ~/.dircolors)
# shellcheck disable=SC2046
test -f ~/.dircolors && eval $(dircolors ~/.dircolors)
test -d ~/dotfiles/bash_completion && {
@ -65,6 +62,26 @@ test -d ~/dotfiles/bash_completion && {
done;
}
# man in color with less
# from https://unix.stackexchange.com/questions/108699/documentation-on-less-termcap-variables
# export LESS_TERMCAP_mb=$'\e[5;31m' # blink
# export LESS_TERMCAP_md=$'\e[1;33m' # bold
# export LESS_TERMCAP_me=$'\e[0m' # no bold, blink, underline
# export LESS_TERMCAP_so=$'\e[7m' # reverse
# export LESS_TERMCAP_se=$'\e[27m' # no reverse
# export LESS_TERMCAP_us=$'\e[4;32m' # underline
# export LESS_TERMCAP_ue=$'\e[24m' # no underline
# https://wiki.archlinux.org/title/Color_output_in_console#Using_less
export MANPAGER="less -R --use-color -Dsc -Dk+r -Dd+g -Du+c -DPgb -DEbR"
export MANROFFOPT="-P -c"
# make less more friendly for non-text input files, see lesspipe(1)
[ -x /usr/bin/lesspipe.sh ] && eval "$(lesspipe.sh)"
# LESS options
#export LESS="-FRX"
# startship
# https://starship.rs/
type -t starship >/dev/null && {
@ -89,7 +106,7 @@ export MANPATH=$HOME/.local/share/man:
# od it in .bash_profile if [ -e /home/patrick/.nix-profile/etc/profile.d/nix.sh ]; then . /home/patrick/.nix-profile/etc/profile.d/nix.sh; fi
# tmux dirty hack : TERM and SSH_AGENT_PID
test -n "$TMUX" && export TERM="xterm-256color"
# test -n "$TMUX" && export TERM="xterm-256color"
# use gpg-agent for gpg
# from gpg-agent(1)
@ -155,22 +172,40 @@ function _prepend_path() { _append_path -r "$1" "$2"; }
test -d "$HOME/.cargo/bin" && PATH=$(_prepend_path "$PATH" "$HOME/.cargo/bin")
### nodejs
test -d "$HOME/download/nodejs/latest/bin" && PATH=$(_prepend_path "$PATH" "$HOME/download/nodejs/latest/bin")
test -d "$HOME/src/node/current/bin" && PATH=$(_prepend_path "$PATH" "$HOME/src/node/current/bin")
# test -d "$HOME/download/nodejs/latest/bin" && PATH=$(_prepend_path "$PATH" "$HOME/download/nodejs/latest/bin")
# test -d "$HOME/src/node/current/bin" && PATH=$(_prepend_path "$PATH" "$HOME/src/node/current/bin")
### npm in user mode
# test -d "${HOME}/.npm-packages" || mkdir "${HOME}/.npm-packages"
# export NPM_PACKAGES="${HOME}/.npm-packages"
# PATH=$(_prepend_path "$PATH" "$NPM_PACKAGES/bin")
# MANPATH=$(_append_path "$MANPATH" "$NPM_PACKAGES/share/man")
test -d "${HOME}/.npm-packages" || mkdir "${HOME}/.npm-packages"
export NPM_PACKAGES="${HOME}/.npm-packages"
PATH=$(_prepend_path "$PATH" "$NPM_PACKAGES/bin")
MANPATH=$(_append_path "$MANPATH" "$NPM_PACKAGES/share/man")
### yarn
test -d "$HOME/src/yarn/latest/bin" && PATH=$(_prepend_path "$PATH" "$HOME/src/yarn/latest/bin")
# test -d "$HOME/src/yarn/latest/bin" && PATH=$(_prepend_path "$PATH" "$HOME/src/yarn/latest/bin")
### golang - default is $HOME/go/bin
export GOPATH="$HOME/go"
test -d "$HOME"/go/bin && PATH=$(_prepend_path "$PATH" "$HOME/go/bin")
### gobuffalo
type -t buffalo > /dev/null 2>&1 && eval "$(buffalo completion bash)"
function bt {
echo "bash bt $*"
local opt=
test "$#" -ne 0 && opt="-m ""$*"
# shellcheck disable=SC2086
buffalo test $opt | _gotestcolored | less -RF
}
function btv {
echo "bash btv $*"
local opt=
test "$#" -ne 0 && opt="-m ""$*"
# shellcheck disable=SC2086
buffalo test -v $opt | _gotestcolored | less -RF
}
# host specific bash
test -r "$HOME/.bashrc-${HOSTNAME}" && source "$HOME/.bashrc-${HOSTNAME}"
@ -260,7 +295,7 @@ function u () {
# mkcd
function mkcd {
test "x$1" = x && return 1
test -n "$1" || return 1
if test -d "$1"
then
echo "dir '$1' already exists"
@ -307,29 +342,27 @@ function faint () {
# chech all cert/key/csr
function openssl_check_all {
local file="$1"
test -n "${file}" || { echo "Usage: $(basename "$0") <template_file>"; return 1; }
test -f "${file}.csr" && openssl_check_csr "${file}.csr"
test -f "${file}.cert" && openssl_check_cert "${file}.cert"
test -f "${file}.cer" && openssl_check_cert "${file}.cer"
test -f "${file}.crt" && openssl_check_cert "${file}.crt"
test -f "${file}.pem" && openssl_check_cert "${file}.pem"
test -f "${file}.key" && openssl_check_key "${file}.key"
local file2;file2=$(sed 's/\./_/g' <<<"$file")
__openssl_check_all "$file"
# local file2;file2=$(sed 's/\./_/g' <<<"$file")
local file2;file2=${file//./_}
test "$file" = "$file2" && return 0
file="$file2"
test -f "${file}.csr" && openssl_check_csr "${file}.csr"
test -f "${file}.cert" && openssl_check_cert "${file}.cert"
test -f "${file}.cer" && openssl_check_cert "${file}.cer"
test -f "${file}.crt" && openssl_check_cert "${file}.crt"
test -f "${file}.pem" && openssl_check_cert "${file}.pem"
test -f "${file}.key" && openssl_check_key "${file}.key"
__openssl_check_all "$file2"
}
__openssl_check_all () {
test -e "${1}.csr" && openssl_check_csr "${1}.csr"
test -e "${1}.cert" && openssl_check_cert "${1}.cert"
test -e "${1}.cer" && openssl_check_cert "${1}.cer"
test -e "${1}.crt" && openssl_check_cert "${1}.crt"
test -e "${1}.pem" && openssl_check_cert "${1}.pem"
test -e "${1}.key" && openssl_check_key "${1}.key"
}
# check Certificate Signing Request file
function openssl_check_csr {
test -f "$1" || { echo "Usage: $(basename "$0") <csr_file>"; return 1; }
faint "# openssl req -noout -text -verify -in $1"
faint "# openssl req -noout -text -verify -in $1 | grep Subject:"
openssl req -noout -text -verify -in "$1" | grep Subject:
faint "# openssl req -noout -modulus -in $1 | openssl md5 "
openssl req -noout -modulus -in "$1" | openssl md5
@ -362,12 +395,12 @@ function openssl_check_https {
function openssl_check_protocol {
test -n "$1" || { echo "Usage: $(basename "$0") mon.site.example.com"; return 1; }
faint "# openssl s_client -servername $1 -connect $1 | egrep 'Protocol|Cipher'"
openssl s_client -servername "$1" -connect "$1" <> /dev/null | egrep 'Protocol|Cipher'
openssl s_client -servername "$1" -connect "$1" <> /dev/null | grep -E 'Protocol|Cipher'
}
# check certificat file dates
function openssl_check_cert_validity {
test -n "$1" || { echo "Usage: $(basename "$0") mon.site.example.com:443"; return 1; }
faint "# openssl s_client -servername ${1%:*} -connect '$1' < /dev/null 2>/dev/null | openssl x509 -noout -dates"
faint "# openssl s_client -servername ${1%:*} -connect $1 < /dev/null 2>/dev/null | openssl x509 -noout -dates"
openssl s_client -servername "${1%:*}" -connect "$1" < /dev/null 2>/dev/null | openssl x509 -noout -dates
#
@ -380,7 +413,7 @@ function openssl_check_cert_validity {
# le certificat
local dest_cert;dest_cert=$(mktemp)
(openssl s_client -connect "$1" < /dev/null 2>&1 | sed -n '/-----BEGIN/,/-----END/p') > "$dest_cert"
openssl s_client -connect "$1" < /dev/null 2>&1 | sed -n '/-----BEGIN/,/-----END/p' > "$dest_cert"
# la chaine de certificat
local chain_cert;chain_cert=$(mktemp)
# openssl s_client -showcerts -connect $1 < /dev/null 2>&1 | sed -n '/-----BEGIN/,/-----END/p' | sed -E '/^---/d' > $chain_cert
@ -397,6 +430,8 @@ function openssl_check_cert_validity {
faint "# openssl ocsp -issuer $onlychain_cert -cert $dest_cert -text -url $ocsp"
openssl ocsp -issuer "$onlychain_cert" -cert "$dest_cert" -url "$ocsp" -text 2>/dev/null | grep "$dest_cert" 2>/dev/null | awk -F " " '{print $2}'
# rm -rf "$dest_cert" "$chain_cert" "$onlychain_cert"
}
function curl_check_https {
@ -459,7 +494,7 @@ EOT
# video
function videoprobe {
test -f "$1" || return 127
ffprobe "$1" 2>&1 | egrep 'Stream|Duration'
ffprobe "$1" 2>&1 | grep -E 'Stream|Duration'
}
function videomakefilm {
# from https://trac.ffmpeg.org/wiki/Encode/H.264
@ -511,6 +546,7 @@ comment () {
}
# terraform env
# shellcheck disable=SC1091
test -r /home/terraform/.terraform_pipelinerc && source /home/terraform/.terraform_pipelinerc
# echo "SSH_AUTH_SOCK=$SSH_AUTH_SOCK"
@ -531,7 +567,10 @@ then
PATH="/home/patrick/perl5/bin${PATH:+:${PATH}}"; export PATH;
PERL5LIB="/home/patrick/perl5/lib/perl5${PERL5LIB:+:${PERL5LIB}}"; export PERL5LIB;
PERL_LOCAL_LIB_ROOT="/home/patrick/perl5${PERL_LOCAL_LIB_ROOT:+:${PERL_LOCAL_LIB_ROOT}}"; export PERL_LOCAL_LIB_ROOT;
PERL_MB_OPT="--install_base \"/home/patrick/perl5\""; export PERL_MB_OPT;
# shellcheck disable=2089
PERL_MB_OPT='--install_base "/home/patrick/perl5"'
# shellcheck disable=2090
export PERL_MB_OPT;
fi
# pyenv
@ -549,4 +588,3 @@ export SHELLCHECK_OPTS="-x"
echo "<< .bashrc"
# end .bashrc

View File

@ -0,0 +1,37 @@
#/usr/bin/env bash
_buffalo_complete()
{
local cur prev
COMPREPLY=()
cur=${COMP_WORDS[COMP_CWORD]}
prev=${COMP_WORDS[COMP_CWORD-1]}
if [ $COMP_CWORD -eq 1 ]; then
COMPREPLY=( $(compgen -W "build db destroy dev fix generate help info new pop routes setup task test version" -- $cur) )
elif [ $COMP_CWORD -eq 2 ]; then
case "$prev" in
-*)
COMPREPLY=( $(compgen -W "h -help" -- $cur) )
;;
"pop"|"db")
COMPREPLY=( $(compgen -W "create destroy drop fix generate migrate reset schema version" -- $cur) )
;;
"destroy")
COMPREPLY=( $(compgen -W "action mailer model resource" -- $cur) )
;;
"generate")
COMPREPLY=( $(compgen -W "action docker mailer resource swagger task" -- $cur) )
;;
"help")
COMPREPLY=( $(compgen -W "build db destroy dev fix generate help info new pop routes setup task test version" -- $cur) )
;;
*)
;;
esac
fi
return 0
} &&
complete -F _buffalo_complete buffalo