From d2dad3460399150447f8ede875a469cdf7cd5f31 Mon Sep 17 00:00:00 2001 From: Case Duckworth Date: Tue, 13 Sep 2022 18:06:16 -0500 Subject: meh. --- bash/aliases.bash | 19 +++++++------ bash/bashrc | 1 + bash/functions.bash | 33 ++++++++++++++++++++-- bash/prompt.bash | 80 ++++++++++++++++++++++++++++------------------------- readline/inputrc | 6 +++- 5 files changed, 89 insertions(+), 50 deletions(-) diff --git a/bash/aliases.bash b/bash/aliases.bash index 7b5ed55..e29f62a 100644 --- a/bash/aliases.bash +++ b/bash/aliases.bash @@ -2,15 +2,15 @@ # sudo sudo_cmds=( - shutdown - reboot - halt - mount - umount - visudo + shutdown + reboot + halt + mount + umount + visudo ) for cmd in "${sudo_cmds[@]}"; do - alias $cmd="sudo $cmd" + alias $cmd="sudo $cmd" done # LS @@ -20,7 +20,7 @@ alias ll='ls -l' alias tree='tree -F' # make locally -alias lake='make PREFIX=~/usr' +alias lake='make PREFIX=$HOME/usr ' # bash meta alias rebash='source ~/.bash_profile' @@ -31,5 +31,6 @@ alias emacs_goddamnit='pushd ~/.emacs.d;emacs --debug-init;popd' # other alias radio=radish if ! command -v fd >/dev/null 2>&1; then - alias fd=fdfind + alias fd=fdfind fi + diff --git a/bash/bashrc b/bash/bashrc index f9f17e7..63e56d4 100644 --- a/bash/bashrc +++ b/bash/bashrc @@ -52,4 +52,5 @@ for f in "${BASH_SOURCE_LAST[@]}"; do fi done +#ddate '+%{%A, %d %B%}, %Y%N (%H)' true diff --git a/bash/functions.bash b/bash/functions.bash index c5bcddb..64e8001 100644 --- a/bash/functions.bash +++ b/bash/functions.bash @@ -48,15 +48,42 @@ please() { # please [COMMAND...] mkcd() { if [ $# -lt 1 ]; then command cd - return + return "$?" + fi + if [ "x$1" = x- ]; then + command cd - + return "$?" fi if ! [ -d "$1" ]; then - read -p "$1 doesn't exist. Create (Y/n)? " yn + read -p "$1 doesn't exist. Create (y/N)? " yn case "$yn" in n* | N*) return 1 ;; - *) mkdir -p "$1" ;; + y* | Y*) mkdir -p "$1" ;; + *) return 1 ;; esac fi command cd "$1" } alias cd='mkcd ' + +# from tomasino +# alias julian='echo "x = $(date +%s); scale=5; x / 86400 + 2440587.5" | bc' +julian() { + echo "x = $(date ${1:+-d "$*"} +%s); scale=5; x / 86400 + 2440587.5" | bc +} + +# find files for pipelines +f() { + find "${1:-$PWD}" -depth | + while read -r file; do + printf '%q\n' "$file" + done +} + +words() { + grep "$1" /usr/share/dict/words +} + +dict() { + curl "dict://dict.org/d:$1" | less +} diff --git a/bash/prompt.bash b/bash/prompt.bash index 15fdb41..06ca638 100644 --- a/bash/prompt.bash +++ b/bash/prompt.bash @@ -1,42 +1,48 @@ # bash prompt if [[ -n "$INSIDE_EMACS" ]]; then - PS1=" \n\[\e[34m\]\$ \[\e[0m\]" + PS1="\n\[\e[34m\]\$ \[\e[0m\]" else - PS1= - - # user, host, and cwd - PROMPT_DIRTRIM=3 # how many dirs above current to print (rest are '...') - PS1+='\[\e[0;46m\]\u@\h \w' - - # git bit - # see https://unix.stackexchange.com/questions/278206 - possible_git_prompt_locations=( - /usr/share/git/git-prompt.sh # Arch, etc. (default?) - /usr/lib/git-core/git-sh-prompt # Debian, Ubuntu ... - /usr/share/git-core/contrib/completion/git-prompt.sh # Fedora ?? - # I have yet to find Alpine's git prompt location. - ) - - for file in "${possible_git_prompt_locations[@]}"; do - if [[ -f "$file" ]]; then - source "$file" && - PS1+='\[\e[35m\]$(__git_ps1)' - break - fi - done - - # 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+='; ' + PS1= + + # user, host, and cwd + PROMPT_DIRTRIM=3 # how many dirs above current to print (rest are '...') + PS1+='\[\e[0;46m\]\u@\h \w' + + # git bit + # see https://unix.stackexchange.com/questions/278206 + possible_git_prompt_locations=( + /usr/share/git/git-prompt.sh # Arch, etc. (default?) + /usr/lib/git-core/git-sh-prompt # Debian, Ubuntu ... + /usr/share/git-core/contrib/completion/git-prompt.sh # Fedora ?? + # I have yet to find Alpine's git prompt location. + ) + + for file in "${possible_git_prompt_locations[@]}"; do + if [[ -f "$file" ]]; then + source "$file" && + PS1+='\[\e[35m\]$(__git_ps1)' + break + fi + done + + # 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\]' + + # terminal title (current directory) + __prompt_term_title() { + printf '\033]0;%s\007\n' "$*" + } + PS1+='\[$(__prompt_term_title "$USER@$(hostname): $PWD")\]' + + # delimiter + PS1+='; ' fi diff --git a/readline/inputrc b/readline/inputrc index 424e7d9..20f3251 100644 --- a/readline/inputrc +++ b/readline/inputrc @@ -8,7 +8,7 @@ $include /etc/inputrc "\C-n":history-search-forward # Show completions using LS_COLORS -set colored-stats On +set colored-stats Off # Ignore case in completions set completion-ignore-case On # Show ... if common prefix is longer than 3 characters @@ -20,3 +20,7 @@ set show-all-if-ambiguous On set show-all-if-unmodified On # Show types (like ls -F) set visible-stats On +# Better pasting +set enable-bracketed-paste on +# Blink parens +set blink-matching-paren on -- cgit 1.4.1-21-gabe81