From e292eb508413b9174684a8e75c93474a7f5351ee Mon Sep 17 00:00:00 2001 From: Case Duckworth Date: Mon, 23 Aug 2021 23:07:31 -0500 Subject: Initial --- bash/aliases.bash | 26 ++++++++++++++++++++++++++ bash/blesh.bash.disable | 1 + bash/dircolors.bash | 1 + bash/functions.bash | 11 +++++++++++ bash/guix.bash | 3 +++ bash/history.bash | 35 +++++++++++++++++++++++++++++++++++ bash/man.bash | 9 +++++++++ bash/please.bash | 14 ++++++++++++++ bash/prompt.bash | 25 +++++++++++++++++++++++++ 9 files changed, 125 insertions(+) create mode 100644 bash/aliases.bash create mode 100644 bash/blesh.bash.disable create mode 100644 bash/dircolors.bash create mode 100644 bash/functions.bash create mode 100644 bash/guix.bash create mode 100644 bash/history.bash create mode 100644 bash/man.bash create mode 100644 bash/please.bash create mode 100644 bash/prompt.bash (limited to 'bash') diff --git a/bash/aliases.bash b/bash/aliases.bash new file mode 100644 index 0000000..f2d6776 --- /dev/null +++ b/bash/aliases.bash @@ -0,0 +1,26 @@ +# Bash aliases + +# sudo +sudo_cmds=( + shutdown + reboot + halt + mount + umount + visudo +) +for cmd in "${sudo_cmds[@]}"; do + alias $cmd="sudo $cmd" +done + +# LS +alias ls='ls -F --color=auto' +alias ll='ls -l' +# tree +alias tree='tree -F' + +# make locally +alias lake='make PREFIX=~/usr' + +# bash meta +alias rebash='source ~/.bash_profile' diff --git a/bash/blesh.bash.disable b/bash/blesh.bash.disable new file mode 100644 index 0000000..9fc617b --- /dev/null +++ b/bash/blesh.bash.disable @@ -0,0 +1 @@ +source "$XDG_DATA_HOME/blesh/ble.sh" diff --git a/bash/dircolors.bash b/bash/dircolors.bash new file mode 100644 index 0000000..597ee95 --- /dev/null +++ b/bash/dircolors.bash @@ -0,0 +1 @@ +eval $(dircolors --sh "${XDG_CONFIG_HOME:-$HOME/.config}/dircolors") diff --git a/bash/functions.bash b/bash/functions.bash new file mode 100644 index 0000000..058e0f9 --- /dev/null +++ b/bash/functions.bash @@ -0,0 +1,11 @@ +memq() { # memq ITEM ARRAY + # Test whether an ITEM is a member of ARRAY. + # Pass ARRAY as ${ARRAY[@]}. + local e needle="$1"; shift + for e; do + [[ "$e" == "$needle" ]] && { + return 0 + } + done + return 1 +} diff --git a/bash/guix.bash b/bash/guix.bash new file mode 100644 index 0000000..127afef --- /dev/null +++ b/bash/guix.bash @@ -0,0 +1,3 @@ +export GUIX_PROFILE="$HOME/.config/guix/current" + +. "$GUIX_PROFILE/etc/profile" diff --git a/bash/history.bash b/bash/history.bash new file mode 100644 index 0000000..95edf9d --- /dev/null +++ b/bash/history.bash @@ -0,0 +1,35 @@ +# Bash history settings +# I don't export any variables in this file because history settings +# really only apply in an interactive session. + +# XDG compliance +HISTFILE="$XDG_DATA_HOME/bash/history" +mkdir -p "$XDG_DATA_HOME/bash" + +# Don't truncate history +HISTFILESIZE=-1 # numeric values less than zero => don't truncate +HISTSIZE=100000 # ideally, I wouldn't truncate at all, but after a while shell +# startup might be affected. + +# Append the history to HISTFILE. +shopt -s histappend + +# History editing with readline +shopt -s histreedit # allow re-editing of a failed history substitution +shopt -s histverify # verify a history expansion before running it + +# Save command invocation time to HISTFILE, and format it thusly +HISTTIMEFORMAT="%F %T " + +# Erase all duplicates before saving the current line +HISTCONTROL=erasedups +# Don't save some commands to history +# "'HISTIGNORE' subsumes the function of 'HISTCONTROL'. A pattern of +# '&' is identical to 'ignoredups', and a pattern of '[ ]*' is +# identical to 'ignorespace'." -- info (bash)Bash Variables +HISTIGNORE='&:[ ]*' +# Other commands to ignore +HISTIGNORE="$HISTIGNORE:ls:exit:cd" + +# Automatically append to HISTFILE on every command +PROMPT_COMMAND="history -a; ${PROMPT_COMMAND:-:}" diff --git a/bash/man.bash b/bash/man.bash new file mode 100644 index 0000000..4927952 --- /dev/null +++ b/bash/man.bash @@ -0,0 +1,9 @@ +export MANWIDTH=80 + +# on smaller terminals, use their width +# (cf. https://wiki.archlinux.org/index.php/Man_page#Page_width) +man() { + local width=$(tput cols) + [ $width -gt $MANWIDTH ] && width=$MANWIDTH + env MANWIDTH=$width man "$@" +} diff --git a/bash/please.bash b/bash/please.bash new file mode 100644 index 0000000..179ed17 --- /dev/null +++ b/bash/please.bash @@ -0,0 +1,14 @@ +# PLEASE +# if run without arguments, run the last command with 'sudo' (aka sudo !!) +# if run WITH arguments, alias as sudo + +please() { + history -d -1 + if [ -z "$1" ]; then + #set -- $(HISTTIMEFORMAT=$'\t' history 2 | sed 's/^.*\t//;q') + set -- $(fc -lnr | sed 1q) + fi + echo >&2 sudo "$@" + history -s sudo "$@" + "${DEBUG:-false}" || sudo "$@" +} diff --git a/bash/prompt.bash b/bash/prompt.bash new file mode 100644 index 0000000..c61266b --- /dev/null +++ b/bash/prompt.bash @@ -0,0 +1,25 @@ +# bash prompt + +PS1= + +# user, host, and cwd +PROMPT_DIRTRIM=3 # how many dirs above current to print (rest are '...') +PS1+='\[\e[36m\]\u@\h \w' + +# git bit +source /usr/share/git/git-prompt.sh && + PS1+='\[\e[35m\]$(__git_ps1)' + +# newline +PS1+='\[\e[0m\]\n' + +# exit code (only if error) +__prompt_exit_code() { + local ec=$? + (( $ec > 0 )) && + printf "$ec" +} +PS1+='\[\e[31m\]$(__prompt_exit_code)\[\e[0m\]' + +# delimiter +PS1+='; ' -- cgit 1.4.1-21-gabe81