1
0
Fork 0
mirror of https://github.com/kastdeur/dotfiles.git synced 2025-06-18 05:06:38 +02:00

[bash] rename bash/rc and bash/bash.d

This commit is contained in:
Eric-Teunis de Boone 2022-02-10 20:07:37 +01:00
parent f67517fdec
commit 6b0d6af2f8
10 changed files with 8 additions and 6 deletions

View file

@ -0,0 +1,52 @@
# enable color support of ls and also add handy aliases
if [ -x /usr/bin/dircolors ]; then
test -r ~/.dircolors && eval "$(dircolors -b ~/.dircolors)" || eval "$(dircolors -b)"
alias ls='ls --color=auto'
alias dir='dir --color=auto'
alias vdir='vdir --color=auto'
alias grep='grep --color=auto'
alias fgrep='fgrep --color=auto'
alias egrep='egrep --color=auto'
alias ip='ip --color=auto'
fi
# some more ls aliases
alias l.='ls -d *'
alias ll='ls -l --si -v --group-directories-first'
alias la='ls -A'
alias lla='ll -A'
alias l='ls -CF'
# make mkdir nicer
alias mkdir='mkdir -p -v'
# Use vim if possible instead of vi
if command -v vim > /dev/null; then
alias vi='vim'
else
alias vim='vi'
fi
alias e="${EDITOR:-vi}"
# Alias expansion in sudo arguments
alias sudo='sudo '
# Reload bashrc
alias bashreload="source ~/.bashrc"
# Easy calculator instead of bc
alias pc='python -ic "from __future__ import division; from math import *"'
# Moving around
alias ~='cd ~'
alias ..='cd ..'
alias ...='cd ../../'
# Computer control
alias blank='sleep 1s && xset dpms force off'
alias lock='blank; xscreensaver-command --lock'
# whatever
alias shrug="echo '¯\_(ツ)_/¯'"
alias pinguin="echo 🐧"

View file

@ -0,0 +1,17 @@
### Colors to Vars ### {{{
## Inspired by http://wiki.archlinux.org/index.php/Color_Bash_Prompt#List_of_colors_for_prompt_and_Bash
## Terminal Control Escape Sequences: http://www.termsys.demon.co.uk/vtansi.htm
## Consider using some of: https://gist.github.com/bcap/5682077#file-terminal-control-sh
## Can unset with `unset -v {,B,U,I,BI,On_,On_I}{Bla,Red,Gre,Yel,Blu,Pur,Cya,Whi} RCol`
RCol='\[\e[0m\]' # Text Reset
# Regular Bold Underline High Intensity BoldHigh Intensity Background High Intensity Backgrounds
Bla='\[\e[0;30m\]'; BBla='\[\e[1;30m\]'; UBla='\[\e[4;30m\]'; IBla='\[\e[0;90m\]'; BIBla='\[\e[1;90m\]'; On_Bla='\[\e[40m\]'; On_IBla='\[\e[0;100m\]';
Red='\[\e[0;31m\]'; BRed='\[\e[1;31m\]'; URed='\[\e[4;31m\]'; IRed='\[\e[0;91m\]'; BIRed='\[\e[1;91m\]'; On_Red='\[\e[41m\]'; On_IRed='\[\e[0;101m\]';
Gre='\[\e[0;32m\]'; BGre='\[\e[1;32m\]'; UGre='\[\e[4;32m\]'; IGre='\[\e[0;92m\]'; BIGre='\[\e[1;92m\]'; On_Gre='\[\e[42m\]'; On_IGre='\[\e[0;102m\]';
Yel='\[\e[0;33m\]'; BYel='\[\e[1;33m\]'; UYel='\[\e[4;33m\]'; IYel='\[\e[0;93m\]'; BIYel='\[\e[1;93m\]'; On_Yel='\[\e[43m\]'; On_IYel='\[\e[0;103m\]';
Blu='\[\e[0;34m\]'; BBlu='\[\e[1;34m\]'; UBlu='\[\e[4;34m\]'; IBlu='\[\e[0;94m\]'; BIBlu='\[\e[1;94m\]'; On_Blu='\[\e[44m\]'; On_IBlu='\[\e[0;104m\]';
Pur='\[\e[0;35m\]'; BPur='\[\e[1;35m\]'; UPur='\[\e[4;35m\]'; IPur='\[\e[0;95m\]'; BIPur='\[\e[1;95m\]'; On_Pur='\[\e[45m\]'; On_IPur='\[\e[0;105m\]';
Cya='\[\e[0;36m\]'; BCya='\[\e[1;36m\]'; UCya='\[\e[4;36m\]'; ICya='\[\e[0;96m\]'; BICya='\[\e[1;96m\]'; On_Cya='\[\e[46m\]'; On_ICya='\[\e[0;106m\]';
Whi='\[\e[0;37m\]'; BWhi='\[\e[1;37m\]'; UWhi='\[\e[4;37m\]'; IWhi='\[\e[0;97m\]'; BIWhi='\[\e[1;97m\]'; On_Whi='\[\e[47m\]'; On_IWhi='\[\e[0;107m\]';
### End Color Vars ### }}}

View file

@ -0,0 +1,15 @@
# .bash_files
# Setup gpg agent info
# if not running, set one up
GPG_AGENT_INFO="${HOME}/.gpg-agent-info"
if [ -f "${GPG_AGENT_INFO}" ]; then
source "${GPG_AGENT_INFO}"
export GPG_AGENT_INFO
export SSH_AUTH_SOCK
export SSH_AGENT_PID
else
/usr/bin/gpg-agent --daemon --write-env-file "${GPG_AGENT_INFO}"
fi

View file

@ -0,0 +1,17 @@
# don't put duplicate lines or lines starting with space in the history.
# See bash(1) for more options
HISTCONTROL=ignoreboth
# append to the history file, don't overwrite it
shopt -s histappend
# for setting history length see HISTSIZE and HISTFILESIZE in bash(1)
HISTSIZE=10000
HISTFILESIZE=20000
# check the window size after each command and, if necessary,
# update the values of LINES and COLUMNS.
shopt -s checkwinsize
# If set, the pattern "**" used in a pathname expansion context will
# match all files and zero or more directories and subdirectories.
#shopt -s globstar

View file

@ -0,0 +1,18 @@
#!/bin/bash
function data_url() {
if [ -z "$1" ]; then
cat << EndOfMessage
Create a data URL that can be directly used in HTML.
Usage: data_url <path_to_file>
EndOfMessage
return
fi
local mime_type base64
mime_type=$(file -b --mime-type "$1")
if [[ "$mime_type" == 'image/svg' ]]; then
mime_type='image/svg+xml'
fi
base64=$(base64 "$1")
echo "data:$mime_type;base64,$base64";
}

View file

@ -0,0 +1,15 @@
# Enable password-storage and its bash completion
PASSDIR="${DOTFILES}/.password-store"
# Only do this when the submodule is loaded
if [ -d "${PASSDIR}/src" ]; then
source "${PASSDIR}/src/completion/pass.bash-completion"
# If pass not registered as executable in your path
# Make an alias
if [[ $(command -v pass) ]]; then
alias pass="${PASSDIR}/src/password-store.sh"
fi
fi

View file

@ -0,0 +1,329 @@
# .bash_files
# /PS
# uncomment for a colored prompt, if the terminal has the capability; turned
# off by default to not distract the user: the focus in a terminal window
# should be on the output of commands, not on the prompt
force_color_prompt=yes
if [ -n "$force_color_prompt" ]; then
if [ -x /usr/bin/tput ] && tput setaf 1 >&/dev/null; then
# We have color support; assume it's compliant with Ecma-48
# (ISO/IEC-6429). (Lack of such support is extremely rare, and
# a case would tend to support setf rather than setaf.)
color_prompt=yes
else
color_prompt=
fi
fi
# Make sure we have the VTE thing when we define our prompt command
#if [ $TILIX_ID ] || [ $VTE_VERSION ]; then
#source /etc/profile.d/vte.sh
#fi
# Old PS1
#if [ "$color_prompt" = yes ]; then
# PS1='${debian_chroot:+($debian_chroot)}\[\033[00;32m\]\u@\H\[\033[00m\] \[\033[0;33;40m\](\t)\[\033[00m\] \[\033[01;34m\]\[$(ls |wc -l)\]@\W\[\033[00m\]:\$ '
#else
# PS1='${debian_chroot:+($debian_chroot)}\u@\H (\t) \[$(ls | wc -l)\]@\W:\$ '
#fi
function color() {
if [ -n "$force_color_prompt" ] ; then
if [ -n "$color_prompt" ] ; then
return 0
else
return 1
fi
else
return 1
fi
}
function vte_thing() {
# if [ $TILIX_ID ] || [ $VTE_VERSION ]; then
# __vte_osc7
# fi
true
}
export PROMPT_COMMAND=__prompt_command
function __PS1_hostname() {
# returns a formatted hostname
local color="${2:-$(color)}"
# no colours? no need to run
if ! color ; then
echo "\h";
return
fi
local HOST="${1:-$HOSTNAME}"
local PS1
local NOMATCH
local func_extension="__PS1_hostname_extended"
# check selected hostnames
case "${HOST%%.*}" in
'locksmith') PS1+="${Pur}\h${RCol}";;
'bladesmith') PS1+="${Yel}\h${RCol}";;
'gunsmith') PS1+="${Red}\h${RCol}";;
'goldsmith') PS1+="${IYel}\h${RCol}";;
*) NOMATCH=1;;
esac
if [ -n "${NOMATCH}" ]; then
if [ x$(type -t "$func_extension") = xfunction ]; then
NOMATCH=$($func_extension "$@")
fi
# extended colouring
if [ -z "${NOMATCH}" ]; then
PS1+="${NOMATCH}"
# default colouring
else
PS1+="${Blu}${On_Whi}\h${RCol}";
fi
fi
echo "$PS1"
}
function __colored_username() {
local USER="${1:-$USER}"
local color="${2:-$(color)}"
local PS1
if color ; then
case "${USER}" in
'root') PS1+="${Red}\u${RCol}";;
'kastdeur'|'ericteunis') PS1+="${Gre}\u${RCol}";;
*) PS1+="${Blu}\u${RCol}";;
esac
else
PS1+="\u"
fi
echo "$PS1"
}
function __prompt_command() {
local RETVAL=$?
if [ ! $RETVAL -ne 0 ]; then
RETVAL=0
fi
PS1="${debian_chroot:+($debian_chroot)}"
#Return Value
if [ -n $RETVAL ]; then
PS1+="$(retval ${RETVAL})"
fi
### Add amount of jobs ###
if true; then
PS1+="$(jobscount)"
fi
### Add Git Status ###
if [[ $(command -v git) ]]; then
PS1+="$(git_status) "
fi
#user@hostname
if color ; then
PS1+="$(__colored_username)"
else
PS1+="\u"
fi
PS1+="@"
if color ; then
PS1+="$(__PS1_hostname)"
else
PS1+="\h"
fi
#time w/ seconds
if color ; then
PS1+="${Yel}${On_Bla}"
fi
PS1+="(\t)"
if color ; then
PS1+="${RCol}"
fi
PS1+=" "
#dir count, pwd
if color ; then
PS1+="${BBlu}"
fi
PS1+="\[$(ls |wc -l)\]@\W"
if color ; then
PS1+="${RCol}"
fi
PS1+=" "
## Short prompt
if [ -n "${SHORTPS1}" ]; then
PS1+="\r\n"
fi
#UID
PS1+=':\$ '
# Something for VTE
PS1+=$(vte_thing)
}
function retval() {
### Determine Return Value
local PS1
if [ -z "$color_prompt" ]; then
PS1="[$1] "
else
if [ ! $1 == 0 ]; then
PS1="${Red}x${RCol}"
else
PS1="${Gre}+${RCol}"
fi
fi
echo "${PS1}"
}
### count jobs
function jobscount() {
local stopped=$(jobs -sp | wc -l)
local running=$(jobs -rp | wc -l)
((running+stopped)) && echo -n "${IYel}${running}${RCol}|${Yel}${stopped}${RCol}"
}
function git_status() {
### Determine Git Status
local PS1
local GStat="$(git status --porcelain -b 2>/dev/null | tr '\n' ':')"
if [ "$GStat" ]; then
### Fetch Time Check ### {{{
local LAST=$(stat -c %Y $(git rev-parse --git-dir 2>/dev/null)/FETCH_HEAD 2>/dev/null)
if [ "${LAST}" ]; then
local TIME=$(echo $(date +"%s") - ${LAST} | bc)
## Check if more than 60 minutes since last
if [ "${TIME}" -gt "3600" ]; then
git fetch 2>/dev/null
PS1+='+ '
## Refresh var
local GStat="$(git status --porcelain -b 2>/dev/null | tr '\n' ':')"
fi
fi
### End Fetch Check ### }}}
### Test For Changes ### {{{
## Change this to test for 'ahead' or 'behind'!
local GChanges="$(echo ${GStat} | tr ':' '\n' | grep -v "^$" | grep -v "^\#\#" | wc -l | tr -d ' ')"
if [ "$GChanges" == "0" ]; then
local GitCol=$Gre
else
local GitCol=$Red
fi
### End Test Changes ### }}}
### Find Branch ### {{{
local GBra="$(echo ${GStat} | tr ':' '\n' | grep "^##" | cut -c4- | grep -o "^[a-zA-Z]\{1,\}[^\.]")"
if [ "$GBra" ]; then
if [ "$GBra" == "master" ]; then
local GBra="M" # Because why waste space
fi
else
local GBra="ERROR" # It could happen supposedly?
fi
### End Branch ### }}}
PS1+="${GitCol}[$GBra]${RCol}" # Add result to prompt
### Find Commit Status ### {{{
## Test Modified and Untracked for "0"
# # local GDel="$(echo ${GStat} | tr ':' '\n' | grep -c "^[ MARC]D")"
local GAhe="$(echo ${GStat} | tr ':' '\n' | grep "^##" | grep -o "ahead [0-9]\{1,\}" | grep -o "[0-9]\{1,\}")"
if [ "$GAhe" ]; then
PS1+="${Gre}${RCol}${GAhe}" # Ahead
fi
## Needs a `git fetch`
local GBeh="$(echo ${GStat} | tr ':' '\n' | grep "^##" | grep -o "behind [0-9]\{1,\}" | grep -o "[0-9]\{1,\}")"
if [ "$GBeh" ]; then
PS1+="${Red}${RCol}${GBeh}" # Behind
fi
local GMod="$(echo ${GStat} | tr ':' '\n' | grep -c "^[ MARC]M")"
if [ "$GMod" -gt "0" ]; then
PS1+="${Pur}${RCol}${GMod}" # Modified
fi
local GUnt="$(echo ${GStat} | tr ':' '\n' | grep -c "^\?")"
if [ "$GUnt" -gt "0" ]; then
PS1+="${Yel}?${RCol}${GUnt}" # Untracked
fi
### End Commit Status ### }}}
echo "${PS1}"
fi
}
# Git
# 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
}