30
homedir/.config/bash.d/colours
Normal file
30
homedir/.config/bash.d/colours
Normal file
@@ -0,0 +1,30 @@
|
||||
# Colours
|
||||
|
||||
# Console colours
|
||||
# Black 0;30 Dark Gray 1;30
|
||||
# Blue 0;34 Light Blue 1;34
|
||||
# Green 0;32 Light Green 1;32
|
||||
# Cyan 0;36 Light Cyan 1;36
|
||||
# Red 0;31 Light Red 1;31
|
||||
# Purple 0;35 Light Purple 1;35
|
||||
# Brown 0;33 Yellow 1;33
|
||||
# Light Gray 0;37 White 1;37
|
||||
|
||||
c_black="\[\033[0;30m\]"
|
||||
c_blue="\[\033[0;34m\]"
|
||||
c_green="\[\033[0;32m\]"
|
||||
c_cyan="\[\033[0;36m\]"
|
||||
c_red="\[\033[0;31m\]"
|
||||
c_purple="\[\033[0;35m\]"
|
||||
c_brown="\[\033[0;33m\]"
|
||||
c_lightgray="\[\033[0;37m\]"
|
||||
c_darkgray="\[\033[1;30m\]"
|
||||
c_lightblue="\[\033[1;34m\]"
|
||||
c_lightgreen="\[\033[1;32m\]"
|
||||
c_lightcyan="\[\033[1;36m\]"
|
||||
c_lightred="\[\033[1;31m\]"
|
||||
c_lightpurple="\[\033[1;35m\]"
|
||||
c_yellow="\[\033[1;33m\]"
|
||||
c_white="\[\033[1;37m\]"
|
||||
|
||||
c_reset="\[\e[00m\]"
|
41
homedir/.config/bash.d/common
Normal file
41
homedir/.config/bash.d/common
Normal file
@@ -0,0 +1,41 @@
|
||||
#!/bin/bash
|
||||
|
||||
echo() { printf '%s\n' "$*"; }
|
||||
msg() { printf '%s\n' "$*"; }
|
||||
err() { printf '%s\n' "$*" >&2; }
|
||||
|
||||
set_title() { printf '\033]0;%s\007' "$1"; }
|
||||
|
||||
trap_error() { err "The command has returned a non-zero exit code ($?)."; }
|
||||
|
||||
x() { exec xinit -- -nolisten tcp vt9; }
|
||||
|
||||
is_coreutils() {
|
||||
declare out
|
||||
out=$( df --version 2>/dev/null )
|
||||
|
||||
(( $? )) && {
|
||||
err 'df --version exited with an error. This is not GNU coreutils'
|
||||
return 3
|
||||
}
|
||||
|
||||
[[ "$out" =~ 'GNU coreutils' ]] || {
|
||||
err 'Version output does not contain "GNU coreutils". This is not GNU coreutils.'
|
||||
return 1
|
||||
}
|
||||
}
|
||||
|
||||
fuck() { sudo $(history -p \!\!); }
|
||||
|
||||
err() { printf '%s\n' "$*"; }
|
||||
|
||||
is_function() {
|
||||
[[ $(type -t "$1") == 'function' ]]
|
||||
}
|
||||
|
||||
if is_coreutils; then
|
||||
ls() { $(type -P ls) -l -hb --group-directories-first --color=auto "$@"; }
|
||||
mv() { $(type -P mv) -v "$@"; }
|
||||
cp() { $(type -P cp) -v "$@"; }
|
||||
rm() { $(type -P rm) -v "$@"; }
|
||||
fi
|
28
homedir/.config/bash.d/config
Normal file
28
homedir/.config/bash.d/config
Normal file
@@ -0,0 +1,28 @@
|
||||
# BASH options
|
||||
bash_opts=(
|
||||
'checkwinsize' 'histappend' 'autocd'
|
||||
'checkhash'
|
||||
)
|
||||
shopt -s "${bash_opts[@]}"
|
||||
shopt -u sourcepath
|
||||
|
||||
PROMPT_COMMAND='set_prompt'
|
||||
|
||||
HISTCONTROL="$HISTCONTROL${HISTCONTROL+,}ignoredups"
|
||||
HISTCONTROL='ignoreboth'
|
||||
|
||||
# Environment
|
||||
export LC_ALL='en_US.UTF-8'
|
||||
export EDITOR='editor'
|
||||
export WINEARCH='win32'
|
||||
|
||||
# GPG
|
||||
GPG_TTY=$(tty)
|
||||
export GPG_TTY
|
||||
|
||||
#export TERM='xterm-256color'
|
||||
export COLORTERM='xterm-256color'
|
||||
|
||||
# Specific to this setup
|
||||
alias dotfiles_pull='git -C ~/git/dotfiles pull'
|
||||
alias dotfiles_push='git -C ~/git/dotfiles commit -a; git -C ~/git/dotfiles push'
|
3
homedir/.config/bash.d/local
Normal file
3
homedir/.config/bash.d/local
Normal file
@@ -0,0 +1,3 @@
|
||||
# SSH
|
||||
SSH_AUTH_SOCK="/tmp/${USER}-ssh-auth.sock"
|
||||
export SSH_AUTH_SOCK
|
75
homedir/.config/bash.d/prompt
Normal file
75
homedir/.config/bash.d/prompt
Normal file
@@ -0,0 +1,75 @@
|
||||
#!/bin/bash
|
||||
|
||||
set_prompt() {
|
||||
last_exitcode="$?"
|
||||
|
||||
declare checkmark fancy_x timestamp git_prompt_msg git_status_short git_status_colour git_unstaged git_untracked
|
||||
|
||||
PS1="${c_reset}"
|
||||
|
||||
# Set a fancy symbol to indicate the last exitcode
|
||||
if (( last_exitcode )); then
|
||||
last_exitcode_indicator="${c_red}!${c_reset}"
|
||||
else
|
||||
last_exitcode_indicator="${c_green}.${c_reset}"
|
||||
fi
|
||||
|
||||
# Set the username colour
|
||||
if (( UID )); then
|
||||
user_colour="${c_green}"
|
||||
user_indicator='$'
|
||||
else
|
||||
user_colour="${c_red}"
|
||||
user_indicator='#'
|
||||
fi
|
||||
|
||||
user_indicator='>'
|
||||
|
||||
# Set the git prompt message
|
||||
git rev-parse --git-dir &>/dev/null && {
|
||||
git_current_branch="$(git rev-parse --abbrev-ref HEAD)"
|
||||
|
||||
while read; do
|
||||
case "$REPLY" in
|
||||
(' M'*|A*|D*) git_unstaged=1;;
|
||||
(\?\?*) git_untracked=1;;
|
||||
esac
|
||||
done < <( git status --short )
|
||||
|
||||
(( git_unstaged )) && {
|
||||
git_status_short+='c'
|
||||
git_status_colour="${c_red}"
|
||||
}
|
||||
|
||||
(( git_untracked )) && {
|
||||
git_status_short+='f'
|
||||
git_status_colour="${c_red}"
|
||||
}
|
||||
|
||||
git_status_short=${git_status_short:-ok}
|
||||
git_status_colour=${git_status_colour:-"${c_green}"}
|
||||
|
||||
git_prompt_msg="(${c_cyan}$git_current_branch${c_reset}[${git_status_colour}${git_status_short}${c_reset}]) "
|
||||
}
|
||||
|
||||
set_title "${USER}@${HOSTNAME}"
|
||||
|
||||
if [[ "$PWD" == "$HOME" ]]; then
|
||||
prompt_pwd='~'
|
||||
elif [[ "$PWD" =~ ^"$HOME" ]]; then
|
||||
prompt_pwd="~/${PWD##*${HOME}/}"
|
||||
else
|
||||
prompt_pwd="$PWD"
|
||||
fi
|
||||
|
||||
prompt=(
|
||||
"${c_reset}"
|
||||
"[${last_exitcode_indicator}]"
|
||||
"${user_colour}${USER}${c_reset}@${c_lightblue}${HOSTNAME}"
|
||||
"$prompt_pwd"
|
||||
"${git_prompt_msg}${user_colour}${user_indicator}"
|
||||
"$c_reset"
|
||||
)
|
||||
|
||||
PS1="${prompt[@]}"
|
||||
}
|
Reference in New Issue
Block a user