config

Personal configuration.
git clone git://code.dwrz.net/config
Log | Files | Refs

commit 1a3e2d6bae8bb4fe8e3dc01f139a1ff76c9494ef
parent 0ebe1ba5f4a995b3a4827bf5654bff0401ff8363
Author: dwrz <dwrz@dwrz.net>
Date:   Mon,  5 Dec 2022 18:21:13 +0000

Add bash

Diffstat:
Abash/bash_logout | 0
Abash/bash_profile | 2++
Abash/bashrc | 214+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 216 insertions(+), 0 deletions(-)

diff --git a/bash/bash_logout b/bash/bash_logout diff --git a/bash/bash_profile b/bash/bash_profile @@ -0,0 +1,2 @@ +[[ -f "${HOME}/.config/profile" ]] && . "${HOME}/.config/profile" +[[ -f "${HOME}/.config/bash/bashrc" ]] && . "${HOME}/.config/bash/bashrc" diff --git a/bash/bashrc b/bash/bashrc @@ -0,0 +1,214 @@ +# Ignore non-interactive shells. +[[ $- != *i* ]] && return + +# Variables +black="\[\e[0;30m\\]" +red="\[\e[0;31m\\]" +green="\[\e[0;32m\\]" +yellow="\[\e[0;33m\\]" +blue="\[\e[0;34m\\]" +magenta="\[\e[0;35m\\]" +cyan="\[\e[0;36m\\]" +white="\[\e[0;37m\\]" + +bold_black="\[\e[01;30m\\]" +bold_red="\[\e[01;31m\\]" +bold_green="\[\e[01;32m\\]" +bold_yellow="\[\e[01;33m\\]" +bold_blue="\[\e[01;34m\\]" +bold_magenta="\[\e[01;35m\\]" +bold_cyan="\[\e[01;36m\\]" +bold_white="\[\e[01;37m\\]" + +icon_checkmark="\342\234\223" +icon_xmark="\342\234\227" +no_color="\[\e[00m\\]" + +# Aliases +alias aoeu="setxkbmap us" +alias asdf="setxkbmap dvorak; xmodmap ~/.config/X11/xmodmap" +alias cal="cal --monday --iso --week" +alias cp="cp -i" +alias cpwd="pwd | tr -d '\n' | xclip" +alias df="df -h" +alias diff="diff --color=auto" +alias dirdu="du -cksh * | sort -hr" +alias e="emacsclient -t" +alias gcc="gcc -O3 -Wall -Wextra -Wstrict-prototypes -std=c17 -pedantic" +alias grep="grep --color=auto" +alias hist="history -a && history -n" +alias hr='printf $(printf "\e[91;1m%%%ds\e[0m\n" $(tput cols)) | tr " " =' +alias j="journalctl" +alias km="xmodmap ~/.config/X11/xmodmap" +alias l="brightnessctl s" +alias la="ls -A" +alias ll="ls -lhF --group-directories-first" +alias lll="ls -alhF --group-directories-first" +alias locks="i3lock -c ffffff -f; systemctl suspend" +alias ls="ls --color=auto" +alias lss="ls -lShr" +alias mic="pactl set-source-mute @DEFAULT_SOURCE@ toggle" +alias mkdir="mkdir -p" +alias mute="pactl set-sink-mute @DEFAULT_SINK@ toggle" +alias mv="mv -i" +alias open="xdg-open" +alias pacman="doas pacman" +alias qd="diff --side-by-side --suppress-common-lines" +alias rb=". ~/.bashrc" +alias rm="rm -I" +alias s="systemctl" +alias scrcpy="scrcpy --stay-awake --turn-screen-off" +alias se="sync-email" +alias sp="tmux new-session -A -s scratch" +alias t="tree -CL 1" +alias tt="tree -CL 2" +alias ttt="tree -CL 3" +alias timers="systemctl --user -all list-timers" +alias tree="tree -C" +alias unread="notmuch search tag:unread" + +# Functions +d() { + case "$1" in + "iso") date '+%Y-%m-%dT%H:%M:%S%:z' | tee /dev/tty | xclip ;; + "mime") date '+%a, %d %b %Y %H:%M:%S %z' | tee /dev/tty | xclip ;; + "unix") date +%s | xclip ;; + # u2h coverts UNIX to ISO. + "u2h") date -d "@$2" '+%Y-%m-%dT%H:%M:%S%:z' | tee /dev/tty | xclip ;; + *) date "$@" | xclip + esac +} + +## fd: find directories +fd() { + find . -type d -iname '*'"$*"'*' -ls ; +} + +## ff: find files +ff() { + find . -type f -iname '*'"$*"'*' -ls ; +} + +repeat() { + local c max + max="$1"; shift; + for ((c=1; c <= max ; c++)); do + "$@"; + done +} + +ts() { + local session="$1" + if [[ -z "$session" ]]; then + session="main" + fi + + tmux new-session -A -s "$session" +} + +# Options +complete -cf doas + +set -o emacs +set -o notify +set -o noclobber + +shopt -s cdspell +shopt -s checkjobs +shopt -s checkwinsize +shopt -s cmdhist +shopt -s complete_fullquote +shopt -s dirspell +shopt -s dotglob +shopt -s expand_aliases +shopt -s extquote +shopt -s force_fignore +shopt -s histappend +shopt -s histreedit +shopt -s histverify +shopt -s hostcomplete +shopt -s interactive_comments +shopt -s nullglob +shopt -s progcomp +shopt -s promptvars +shopt -s sourcepath + +# Prompt +timer_now() { + date +%s%N +} + +timer_start() { + timer_start=${timer_start:-$(timer_now)} +} + +timer_stop() { + local delta_us=$((($(timer_now) - timer_start) / 1000)) + local us=$((delta_us % 1000)) + local ms=$(((delta_us / 1000) % 1000)) + local s=$(((delta_us / 1000000) % 60)) + local m=$(((delta_us / 60000000) % 60)) + local h=$((delta_us / 3600000000)) + # Goal: always show around 3 digits of accuracy + if ((h > 0)); then timer_show=${h}h${m}m + elif ((m > 0)); then timer_show=${m}m${s}s + elif ((s >= 10)); then timer_show=${s}.$((ms / 100))s + elif ((s > 0)); then timer_show=${s}.$(printf %03d $ms)s + elif ((ms >= 100)); then timer_show=${ms}ms + elif ((ms > 0)); then timer_show=${ms}.$((us / 100))ms + else timer_show=${us}us + fi + unset timer_start +} + +set_prompt () { + # First, get the exit code of the last command. + last_command=$? + + # Stop the timer. + timer_stop + + # Set the current UTC time. + PS1="$bold_black$(date -u +"%H:%M:%S") " + + # Set the user; red if root, green otherwise. + if [[ "$EUID" == 0 ]]; then + PS1+="$bold_red\\u" + else + PS1+="$bold_green\\u" + fi + + # Set the "@". + PS1+="$bold_green@" + + # Set the host; green for local, yellow for SSH, red for unsecured connection. + if [[ -n "${SSH_CONNECTION}" ]]; then + PS1+="$bold_yellow\\H " + elif [[ "${DISPLAY%%:0*}" != "" ]]; then + PS1+="$bold_red\\H " + else + PS1+="$bold_green\\H " + fi + + # Set the exit code. + PS1+="$bold_black\$last_command " + + # Set a check mark for an exit code of 0 (success). + # Otherwise, set an X mark. + if [[ $last_command == 0 ]]; then + PS1+="$bold_green$icon_checkmark " + else + PS1+="$bold_red$icon_xmark " + fi + + # Set the elapsed time. + # Inherit the color from the preceding mark. + PS1+="($timer_show) " + + # Set the working directory and prompt marker. + # Finally, reset to no color. + PS1+="$bold_blue\\w \\\$$no_color " +} + +trap "timer_start" DEBUG +PROMPT_COMMAND="set_prompt"