#!/bin/bash # # ▒█▀▀▀ ▒█▀▀█ Filip Rojek # ▒█▀▀▀ ▒█▄▄▀ http://git.filiprojek.cz/fr/ # ▒█░░░ ▒█░▒█ http://filiprojek.cz/ # # .bashrc source /etc/profile # If not running interactively, don't do anything [[ $- != *i* ]] && return # PS1 shell color ## simple white ps1 without git #PS1='\[\e[0m\][\[\e[0m\]\u\[\e[0m\]@\[\e[0m\]\H \[\e[0m\]\W\[\e[0m\]]\[\e[0m\]\$ \[\e[0m\]' ## based on: https://www.cyberciti.biz/faq/bash-shell-change-the-color-of-my-shell-prompt-under-linux-or-unix/ ## get current branch in git repo function parse_git_branch() { BRANCH=`git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/\1/'` if [ ! "${BRANCH}" == "" ] then STAT=`parse_git_dirty` echo "[${BRANCH}${STAT}]" else echo "" fi } ## get current status of git repo function parse_git_dirty { status=`git status 2>&1 | tee` dirty=`echo -n "${status}" 2> /dev/null | grep "modified:" &> /dev/null; echo "$?"` untracked=`echo -n "${status}" 2> /dev/null | grep "Untracked files" &> /dev/null; echo "$?"` ahead=`echo -n "${status}" 2> /dev/null | grep "Your branch is ahead of" &> /dev/null; echo "$?"` newfile=`echo -n "${status}" 2> /dev/null | grep "new file:" &> /dev/null; echo "$?"` renamed=`echo -n "${status}" 2> /dev/null | grep "renamed:" &> /dev/null; echo "$?"` deleted=`echo -n "${status}" 2> /dev/null | grep "deleted:" &> /dev/null; echo "$?"` bits='' if [ "${renamed}" == "0" ]; then bits=">${bits}" fi if [ "${ahead}" == "0" ]; then bits="*${bits}" fi if [ "${newfile}" == "0" ]; then bits="+${bits}" fi if [ "${untracked}" == "0" ]; then bits="?${bits}" fi if [ "${deleted}" == "0" ]; then bits="x${bits}" fi if [ "${dirty}" == "0" ]; then bits="!${bits}" fi if [ ! "${bits}" == "" ]; then echo " ${bits}" else echo "" fi } export PS1="\[\e[36m\][\[\e[m\]\[\e[36m\]\u\[\e[m\]\[\e[36m\]@\[\e[m\]\[\e[36m\]\h\[\e[m\]\[\e[36m\] \[\e[m\]\[\e[36m\]\W\[\e[m\]\[\e[36m\]]\[\e[m\]\[\e[32;40m\]\`parse_git_branch\`\[\e[m\]\[\e[36m\]\\$\[\e[m\] " # Functions function convertm() { for f in *.jpg; do convert ./"$f" ./"${f%.}.pdf" done } ## Create new directory and descend into it function mkcd() { mkdir -p "$@" && cd "$@"; } ## Kill all that use port killport () { kill $(lsof -t -i:"$1") } ## Enable runit service (for Void Linux) function sv-enable () { if test -e /etc/sv/$1; then doas ln -sv /etc/sv/$1 /var/service/ else echo "Error: /etc/sv/$1 does not exist" fi } ## Switch keyboard layouts function xkb-switch () { LAYOUT=$(setxkbmap -query | grep layout | awk '{print $2}') if [[ $LAYOUT == "us" ]]; then setxkbmap cz qwerty else setxkbmap us fi } ## Repeat command until exit function dorepeat() { while true; do "$@" sleep 1 echo done } ## Generate random password (default length is 16 chars) function genpasswd() { local l=$1 [ -n "$l" ] || l=16 tr -dc A-Za-z0-9_ < /dev/urandom \ | head -c "$l" | xargs } ## Download m3u8 stream m3u8-download() { youtube-dl --list-formats "$1" echo "enter format code:" read format_code youtube-dl -f $format_code --hls-prefer-native "$1" } ## GPG functions gpg_encrypt () { output=~/"${1}".$(date +%s).enc #gpg --encrypt --armor --output ${output} -r 0x0000 -r 0x0001 -r 0x0002 "${1}" && echo "${1} -> ${output}" gpg --encrypt --armor --output ${output} "${1}" && echo "${1} -> ${output}" } gpg_decrypt () { output=$(echo "${1}" | rev | cut -c16- | rev) gpg --decrypt --output ${output} "${1}" && echo "${1} -> ${output}" } # for spawning new terminal instances in the current working directory in foot terminal osc7_cwd() { local strlen=${#PWD} local encoded="" local pos c o for (( pos=0; pos