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"
shopt -s cdspell
2020-05-14 15:51:29 +00:00
shopt -s dirspell
shopt -s autocd
shopt -s globstar
2014-06-22 16:16:14 +00:00
shopt -s nocaseglob
2022-11-04 14:45:55 +00:00
CDPATH = "~/clones/"
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
export HISTCONTROL = ignoredups
2023-04-17 10:04:33 +00:00
export HISTFILESIZE = 50000
export HISTSIZE = 50000
2014-06-22 16:16:14 +00:00
2023-01-20 12:26:49 +00:00
export PIP_REQUIRE_VIRTUALENV = 1
2014-06-22 16:16:14 +00:00
umask 022
eval "`dircolors`"
2017-08-30 08:02:06 +00:00
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 ))
2017-08-30 08:02:06 +00:00
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 "
# make less more friendly for non-text input files, see lesspipe(1)
2023-05-24 09:35:04 +00:00
# needs: apt install lesspipe source-highlight
export LESSOPEN = "| /usr/share/source-highlight/src-hilite-lesspipe.sh %s"
export LESS = ' -R '
2014-06-22 16:16:14 +00:00
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
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 {} \;'
2021-10-05 02:19:20 +00:00
alias rekey = 'ssh-add -e /usr/lib/x86_64-linux-gnu/opensc-pkcs11.so >/dev/null 2>&1; ssh-add -s /usr/lib/x86_64-linux-gnu/opensc-pkcs11.so'
2014-06-22 16:16:14 +00:00
2019-10-16 14:02:39 +00:00
export PYTHONDEVMODE = y
2018-10-14 20:38:28 +00:00
2023-12-02 23:18:23 +00:00
for extra in /etc/bash_completion ~/.bash_aliases ~/.my_bashrc ~/.git-prompt.sh ~/clones/mdk/compile-python/compile-python.sh ~/clones/mdk/python-prompt/python-prompt.sh
2018-08-12 09:56:25 +00:00
do
if [ -f " $extra " ]
then
. $extra
fi
done
2014-06-22 16:16:14 +00:00
2021-10-13 13:58:43 +00:00
if [ [ " $TERM " != 'dumb' ] ]
then
_TITLE = "\[\e]0;\H \W\a\]"
else
_TITLE = ''
fi
_PREV_FAIL = "\`PREV_FAIL=\$?; if [ \$PREV_FAIL != 0 ]; then echo \[\e[31m\]\$PREV_FAIL \[\e[0m\]; fi\`"
2022-04-23 13:05:51 +00:00
2023-12-01 21:34:41 +00:00
if ! [ [ -f ~/.fonts/dejavu/DejaVuSansMonoNerdFontCompleteMono.ttf ] ]
then
mkdir -p ~/.fonts/dejavu/
wget -qO ~/.fonts/dejavu/DejaVuSansMonoNerdFontCompleteMono.ttf https://github.com/ryanoasis/nerd-fonts/raw/master/patched-fonts/DejaVuSansMono/Regular/complete/DejaVu%20Sans%20Mono%20Nerd%20Font%20Complete%20Mono.ttf
fi
2022-04-23 14:20:57 +00:00
GIT_RED_FG = '\e[38;2;244;77;39m'
GIT_RED_BG = '\e[48;2;244;77;39m'
PY_BLUE_FG = '\e[38;2;53;112;160m'
PY_BLUE_BG = '\e[48;2;53;112;160m'
PY_YELLOW_FG = '\e[38;2;255;222;87m'
PY_YELLOW_BG = '\e[48;2;255;222;87m'
2023-12-02 23:18:23 +00:00
2023-12-03 08:00:54 +00:00
git_prompt( )
{
# Wrapper around __git_ps1
# to not show it when the repo is my dotfiles.
if [ [ " $( git rev-parse --show-toplevel) " != " $HOME " ] ]
then
__git_ps1 " $1 "
fi
}
2023-12-02 23:18:23 +00:00
PY_PS1 = '$(python_prompt "${PY_BLUE_FG}🭮${PY_BLUE_BG}${PY_YELLOW_FG} %s \e[0m${PY_BLUE_FG}🭬\e[0m")'
2023-12-03 08:00:54 +00:00
GIT_PS1 = '$(git_prompt "${GIT_RED_FG}🭮${GIT_RED_BG}\e[97m %s \e[0m${GIT_RED_FG}🭬\e[0m")'
2022-04-23 14:20:57 +00:00
PS1 = " ${ _TITLE } ${ _PREV_FAIL } ${ USERNAME_COLOR } \u\e[0m@ ${ HOSTNAME_COLOR } \H\e[0m:\e[32m\w\e[0m ${ PY_PS1 } ${ GIT_PS1 } \n\$ "
2022-04-23 13:05:51 +00:00
eval " $( direnv hook bash) "
2020-01-08 23:24:54 +00:00
2014-06-22 16:16:14 +00:00
urldecode( )
{
input = " $( [ $# -gt 0 ] && printf "%s\n" " $* " || cat -) "
2023-01-20 12:28:09 +00:00
python -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 -) "
2023-01-20 12:28:09 +00:00
python -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( )
{
2023-12-01 13:53:15 +00:00
find -maxdepth 4 \
2023-01-20 12:29:10 +00:00
\( -name '*~' -o -name '#*#' -o -name .tox -o -name .mypy_cache \) \
-print0 | xargs -0 rm -vfr
2014-06-22 16:16:14 +00:00
}
2019-06-25 14:32:25 +00:00
wyz( )
{
curl https://wyz.fr/ -F" ${ 1 ##*. } =@ $1 "
}
2019-10-17 08:18:37 +00:00
2023-12-01 13:53:15 +00:00
code-block( )
{
printf '```%s\n' " $1 "
cat
printf '```\n'
}
2023-05-24 09:37:23 +00:00
paf( )
{
2023-12-01 13:53:15 +00:00
local SECRET = " $( pass paf) "
2023-05-24 09:37:23 +00:00
local AUTH = " -HAuthorization: Secret $SECRET "
local INSTANCE = "https://p.afpy.org/"
if [ [ $1 = = "--list" ] ]
then
curl " $AUTH " $INSTANCE ::/list/
return
fi
if [ [ $# = = 0 ] ]
then
curl " $AUTH " " $INSTANCE " --data-binary @-
else
curl " $AUTH " " $INSTANCE " " ${ @/*/-F&=@& } "
fi
}
2021-11-06 09:26:03 +00:00
e( )
{
emacsclient --no-wait " $@ "
}
2022-09-02 08:39:22 +00:00
venv( )
{
2023-12-02 22:22:52 +00:00
# Simple helper to use direnv to create Python venvs.
#
# See https://github.com/pappasam/jedi-language-server/issues/199#issuecomment-1836880575
# for more context.
printf "VIRTUAL_ENV=.venv\nlayout python3\n" > .envrc
2023-01-20 12:48:24 +00:00
direnv allow .
2022-09-02 08:39:22 +00:00
}
2022-11-04 14:45:55 +00:00
github-gpg( )
{
curl https://github.com/$1 .gpg | gpg --import-options show-only --import -
}
download-random-pypi-proj( )
{
PKG_URL = " $( curl -s https://pypi.org/rss/packages.xml | grep -o 'https://pypi.org/project/[^ <]*' | shuf | head -n 1 | sed 's/project/simple/g' ) "
ARCHIVE_URL = " $( curl -s " $PKG_URL " | grep -o 'https://[^ "#]*' | tail -n 1) "
TMP = pypi_$RANDOM $RANDOM
mkdir /tmp/$TMP /
cd /tmp/$TMP
wget " $ARCHIVE_URL "
2022-09-02 08:39:22 +00:00
}
2023-04-17 10:04:44 +00:00
digns( )
{
local SOA = ""
local name = " $1 "
while [ -z " $SOA " ]
do
SOA = " $( dig SOA " $name " | awk '/^[^;].*SOA/{print $1}' ) "
name = " $( printf "%s" " $name " | sed 's/^[^.]\+\.//' ) "
if [ [ -z " $SOA " ] ] && ! [ [ " $name " = ~ \. ] ]
then
printf "Cannot find SOA for %s.\n" " $1 " >& 2
return 1
fi
done
dig " @ $( dig NS " $SOA " +short | head -n 1) " " $@ "
}
2023-12-01 13:53:15 +00:00
compress-video( )
{
local IFILE = " $1 "
local OFILE = " ${ IFILE %.* } " .m4v
HandBrakeCLI -Z "Fast 720p30" -i " $IFILE " -o " $OFILE "
ls -lah " $IFILE " " $OFILE "
cp -a --attributes-only " $IFILE " " $OFILE "
rm -i " $IFILE "
}