diff --git a/.bashrc b/.bashrc index a08bcec..b999ac6 100644 --- a/.bashrc +++ b/.bashrc @@ -55,10 +55,6 @@ export LESSOPEN="| /usr/share/source-highlight/src-hilite-lesspipe.sh %s" export LESS=' -R ' -if ! [ -f "$HOME/.git-prompt.sh" ] -then - wget -q -O "$HOME/.git-prompt.sh" https://raw.githubusercontent.com/git/git/master/contrib/completion/git-prompt.sh -fi alias ls='ls --color=auto' alias fingerprint='find /etc/ssh -name "*.pub" -exec ssh-keygen -l -f {} \;' @@ -66,9 +62,14 @@ alias rekey='ssh-add -e /usr/lib/x86_64-linux-gnu/opensc-pkcs11.so >/dev/null 2> export PYTHONDEVMODE=y +if ! [[ -f "$HOME/.git-prompt.sh" ]] +then + wget -q -O "$HOME/.git-prompt.sh" https://raw.githubusercontent.com/git/git/master/contrib/completion/git-prompt.sh +fi + 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 do - if [ -f "$extra" ] + if [[ -f "$extra" ]] then . $extra fi @@ -93,13 +94,13 @@ 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' + git_prompt() { # Wrapper around __git_ps1 # to not show it when the repo is my dotfiles. - if [[ "$(git rev-parse --show-toplevel)" != "$HOME" ]] + if [[ "$(git rev-parse --show-toplevel 2>/dev/null)" != "$HOME" ]] then __git_ps1 "$1" fi @@ -111,18 +112,6 @@ PS1="${_TITLE}${_PREV_FAIL}${USERNAME_COLOR}\u\e[0m@${HOSTNAME_COLOR}\H\e[0m:\e[ eval "$(direnv hook bash)" -urldecode() -{ - input="$([ $# -gt 0 ] && printf "%s\n" "$*" || cat -)" - python -c "import urllib.parse, sys; print(urllib.parse.unquote(sys.argv[1]))" "$input" -} - -urlencode() -{ - input="$([ $# -gt 0 ] && printf "%s\n" "$*" || cat -)" - python -c "import urllib.parse, sys; print(urllib.parse.quote(sys.argv[1]))" "$input" -} - # Removes *~ and #*# files in curent folder, for a depth limited to 3 folders. clean() { @@ -131,11 +120,6 @@ clean() -print0 | xargs -0 rm -vfr } -wyz() -{ - curl https://wyz.fr/ -F"${1##*.}=@$1" -} - code-block() { printf '```%s\n' "$1" @@ -143,26 +127,6 @@ code-block() printf '```\n' } -paf() -{ - local SECRET="$(pass paf)" - 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 -} - e() { emacsclient --no-wait "$@" @@ -177,47 +141,3 @@ venv() printf "VIRTUAL_ENV=.venv\nlayout python3\n" > .envrc direnv allow . } - -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" -} - -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)" "$@" -} - -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" -} diff --git a/.local/bin/digns b/.local/bin/digns new file mode 100755 index 0000000..b2d2a5a --- /dev/null +++ b/.local/bin/digns @@ -0,0 +1,16 @@ +#!/bin/bash + +SOA="" +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 + exit 1 + fi +done +dig "@$(dig NS "$SOA" +short | head -n 1)" "$@" diff --git a/.local/bin/github-gpg b/.local/bin/github-gpg new file mode 100755 index 0000000..e8ee40d --- /dev/null +++ b/.local/bin/github-gpg @@ -0,0 +1,3 @@ +#!/bin/sh + +curl https://github.com/$1.gpg | gpg --import-options show-only --import - diff --git a/.local/bin/paf b/.local/bin/paf new file mode 100755 index 0000000..bda5373 --- /dev/null +++ b/.local/bin/paf @@ -0,0 +1,18 @@ +#!/bin/bash + +SECRET="$(pass paf)" +AUTH="-HAuthorization: Secret $SECRET" +INSTANCE="https://p.afpy.org/" + +if [[ $1 == "--list" ]] +then + curl "$AUTH" $INSTANCE::/list/ + exit +fi + +if [[ $# == 0 ]] +then + curl "$AUTH" "$INSTANCE" --data-binary @- +else + curl "$AUTH" "$INSTANCE" "${@/*/-F&=@&}" +fi diff --git a/.local/bin/pypi-random-project b/.local/bin/pypi-random-project new file mode 100755 index 0000000..788e8e5 --- /dev/null +++ b/.local/bin/pypi-random-project @@ -0,0 +1,8 @@ +#!/bin/sh + +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" diff --git a/.local/bin/urldecode b/.local/bin/urldecode new file mode 100755 index 0000000..ab8b42f --- /dev/null +++ b/.local/bin/urldecode @@ -0,0 +1,4 @@ +#!/bin/bash + +input="$([ $# -gt 0 ] && printf "%s\n" "$*" || cat -)" +python -c "import urllib.parse, sys; print(urllib.parse.quote(sys.argv[1]))" "$input" diff --git a/.local/bin/urlencode b/.local/bin/urlencode new file mode 100755 index 0000000..8fcf10c --- /dev/null +++ b/.local/bin/urlencode @@ -0,0 +1,4 @@ +#!/bin/bash + +input="$([ $# -gt 0 ] && printf "%s\n" "$*" || cat -)" +python -c "import urllib.parse, sys; print(urllib.parse.unquote(sys.argv[1]))" "$input" diff --git a/.local/bin/video-compress b/.local/bin/video-compress new file mode 100755 index 0000000..37f9bb2 --- /dev/null +++ b/.local/bin/video-compress @@ -0,0 +1,10 @@ +#!/bin/sh + +IFILE="$1" +OFILE="${IFILE%.*}".m4v + +HandBrakeCLI -Z "Fast 720p30" -i "$IFILE" -o "$OFILE" + +ls -lah "$IFILE" "$OFILE" +cp -a --attributes-only "$IFILE" "$OFILE" +rm -i "$IFILE"