dotfiles/.bashrc

174 lines
4.8 KiB
Bash
Raw Normal View History

2014-06-22 16:16:14 +00:00
# If not running interactively, don't do anything more
[ -z "$PS1" ] && return
DEBEMAIL=julien
DEBEMAIL=$DEBEMAIL@
DEBEMAIL=${DEBEMAIL}palard.fr
DEBFULLNAME="Julien Palard"
2018-10-14 20:34:35 +00:00
PATH="$PATH:$HOME/.local/bin"
2014-06-22 16:16:14 +00:00
shopt -s checkwinsize
shopt -s cdspell
shopt -s dirspell 2>/dev/null # Only in bash 4
shopt -s autocd 2>/dev/null # Only in bash 4
shopt -s globstar 2>/dev/null # Only in bash 4
shopt -s nocaseglob
2018-08-12 09:51:32 +00:00
if [ -n "$DISPLAY" ]
then
2016-01-04 09:53:00 +00:00
xset b off
fi
2014-06-22 16:16:14 +00:00
# http://nion.modprobe.de/blog/archives/572-less-colors-for-man-pages.html
export LESS_TERMCAP_mb=$'\E[01;31m' # debut de blink
export LESS_TERMCAP_md=$'\E[01;31m' # debut de gras
export LESS_TERMCAP_me=$'\E[0m' # fin
export LESS_TERMCAP_so=$'\E[01;44;33m' # début de la ligne d'état
export LESS_TERMCAP_se=$'\E[0m' # fin
export LESS_TERMCAP_us=$'\E[01;32m' # début de souligné
export LESS_TERMCAP_ue=$'\E[0m' # fin
export DEBEMAIL DEBFULLNAME
export EDITOR=emacs
2015-11-28 16:57:20 +00:00
export LC_ALL='en_US.utf8'
2014-06-22 16:16:14 +00:00
export HISTCONTROL=ignoredups
export HISTFILESIZE=5000
export HISTSIZE=5000
umask 022
eval "`dircolors`"
set -C
HOSTNAME_SUM=$(cksum <(hostname) | cut -d' ' -f1)
2014-06-22 16:16:14 +00:00
HOSTNAME_BOLD=$(( ($HOSTNAME_SUM + 1) % 2))
HOSTNAME_HUE=$(( ($HOSTNAME_SUM + 3) % 6 + 31))
USERNAME_SUM=$(($(cksum <(whoami) | cut -d' ' -f1) + 5)) # + 5 so root gots red.
2014-06-22 16:16:14 +00:00
USERNAME_BOLD=$(( ($USERNAME_SUM + 1) % 2))
USERNAME_HUE=$(( ($USERNAME_SUM + 2) % 6 + 31))
HOSTNAME_COLOR=$'\E'"[$HOSTNAME_BOLD;${HOSTNAME_HUE}m"
USERNAME_COLOR=$'\E'"[$USERNAME_BOLD;${USERNAME_HUE}m"
WHITE=$'\E[00m'
# make less more friendly for non-text input files, see lesspipe(1)
[ -x /usr/bin/lesspipe ] && eval "$(lesspipe)"
[ "$TERM" != 'linux' -a z"$TERM" != z'eterm-color' ] && TITLE="\[\033]0;\u@\H:\w\a\]" || TITLE=''
2014-09-17 10:19:39 +00:00
export PS1="$TITLE\[$USERNAME_COLOR\]\u\[$WHITE\]@\[$HOSTNAME_COLOR\]\H\[$WHITE\]"
2018-08-12 09:54:14 +00:00
2018-09-25 22:34:18 +00:00
if ! [ -f "$HOME/.git-prompt.sh" ]
2014-09-17 10:19:39 +00:00
then
2018-09-25 22:34:18 +00:00
wget -q -O "$HOME/.git-prompt.sh" https://raw.githubusercontent.com/git/git/master/contrib/completion/git-prompt.sh
2014-09-17 10:19:39 +00:00
fi
2018-08-12 09:54:14 +00:00
export PS1="$PS1"'$(__git_ps1 " (%s)")\$ '
2017-08-30 08:05:14 +00:00
2017-04-29 09:28:30 +00:00
alias ls='ls --color=auto'
2014-06-22 16:16:14 +00:00
alias fingerprint='find /etc/ssh -name "*.pub" -exec ssh-keygen -l -f {} \;'
2017-08-30 08:07:34 +00:00
alias rekey='ssh-add -e /usr/lib/x86_64-linux-gnu/opensc-pkcs11.so; ssh-add -s /usr/lib/x86_64-linux-gnu/opensc-pkcs11.so'
2019-06-18 14:50:29 +00:00
alias json_pp='json_pp -json_opt utf8,pretty,canonical'
2014-06-22 16:16:14 +00:00
export PYTHONSTARTUP=$HOME/.config/pythonstartup.py
2018-08-12 09:56:25 +00:00
for extra in /etc/bash_completion ~/.bash_aliases ~/.my_bashrc ~/.git-prompt.sh
do
if [ -f "$extra" ]
then
. $extra
fi
done
2014-06-22 16:16:14 +00:00
jsonpp()
{
input="$([ $# -gt 0 ] && printf "%s\n" "$*" || cat -)"
if ! [ z"$(which pygmentize)" = z"" ]
then
2017-04-29 09:28:30 +00:00
printf "%s" "$input" | python3 -mjson.tool | pygmentize -l js || printf "%s\n" "$input"
2014-06-22 16:16:14 +00:00
else
2017-04-29 09:28:30 +00:00
printf "%s" "$input" | python3 -mjson.tool || printf "%s\n" "$input"
2014-06-22 16:16:14 +00:00
fi
}
urldecode()
{
input="$([ $# -gt 0 ] && printf "%s\n" "$*" || cat -)"
2017-04-21 12:36:05 +00:00
python3 -c "import urllib.parse, sys; print(urllib.parse.unquote(sys.argv[1]))" "$input"
2014-06-22 16:16:14 +00:00
}
urlencode()
{
input="$([ $# -gt 0 ] && printf "%s\n" "$*" || cat -)"
2017-04-21 12:36:05 +00:00
python3 -c "import urllib.parse, sys; print(urllib.parse.quote(sys.argv[1]))" "$input"
2014-06-22 16:16:14 +00:00
}
# Removes *~ and #*# files in curent folder, for a depth limited to 3 folders.
clean()
{
find -maxdepth 3 -name .emacs_backups -prune \
-o \( -type f -a \
\( -name '*~' -o -name '#*#' \) \
\) \
-print0 | xargs -0 rm -f
}
2017-08-30 08:05:43 +00:00
workon()
{
local VENVS="$HOME/.venvs"
if [ -z "$1" -o z"$1" = z"." ]
then
local VENV_NAME="$(basename "$PWD")"
else
local VENV_NAME="$1"
fi
deactivate >/dev/null 2>/dev/null
2018-08-12 09:58:33 +00:00
mkdir -p "$VENVS"
[ -f "$VENVS/$VENV_NAME/bin/activate" ] || python3 -m venv "$VENVS/$VENV_NAME"
. "$VENVS/$VENV_NAME/bin/activate"
}
2017-04-21 21:18:53 +00:00
2017-08-30 08:05:43 +00:00
_workon()
2017-04-21 21:18:53 +00:00
{
COMPREPLY=( $( compgen -W '$( command ls "$HOME/.venvs" )' -- "${COMP_WORDS[COMP_CWORD]}") )
}
complete -F _workon workon
dotfiles()
{
local CLONE="$HOME/.config/dotfiles-repo/"
mkdir -p ~/.config/
if [ -d "$CLONE" ]
then
git -C "$CLONE" pull --ff-only
else
git clone -q https://github.com/JulienPalard/dotfiles.git "$CLONE"
fi
"$CLONE"/interactive_copy.py "$CLONE" ~/ --exclude README.md .git interactive_copy.py install.sh __pycache__
2018-08-12 10:04:59 +00:00
rm -f "$HOME/.git-prompt.sh"
wget -q -O "$HOME/.git-prompt.sh" https://raw.githubusercontent.com/git/git/master/contrib/completion/git-prompt.sh
}
2018-09-25 17:30:27 +00:00
fontsize()
{
printf '\33]50;%s\007' "xft:LiberationMono:size=$1"
}
2019-06-18 12:47:55 +00:00
pasee()
{
local LOGIN
local PASSWORD
2019-06-25 14:32:25 +00:00
local HOST="${1:-https://id.meltygroup.com/tokens/?idp=meltygroup}"
2019-06-18 12:47:55 +00:00
read -p 'Login: ' LOGIN
read -s -p "Password for $LOGIN: " PASSWORD
echo
2019-06-25 14:32:25 +00:00
JWT="$(curl -s -XPOST -d '{"login": "'"$LOGIN"'", "password": "'"$PASSWORD"'"}' $HOST | jq -r ".access_token")"
2019-06-18 12:47:55 +00:00
AUTH="Authorization: Bearer $JWT"
}
2019-06-25 14:32:25 +00:00
wyz()
{
curl https://wyz.fr/ -F"${1##*.}=@$1"
}