diff options
Diffstat (limited to '.config')
-rw-r--r-- | .config/bash/rc.d/01_unset_prompt_command.sh | 3 | ||||
-rw-r--r-- | .config/bash/rc.d/10_aliases.sh (renamed from .config/bash/rc.d/aliases.sh) | 66 | ||||
-rw-r--r-- | .config/bash/rc.d/10_hist.sh | 9 | ||||
-rw-r--r-- | .config/bash/rc.d/10_misc.sh | 10 | ||||
-rw-r--r-- | .config/bash/rc.d/90_emacs.sh | 63 | ||||
-rw-r--r-- | .config/bash/rc.d/90_term_title.sh | 3 | ||||
-rw-r--r-- | .config/bash/rc.d/99_ps1.sh | 20 | ||||
-rw-r--r-- | .config/bash/rc.d/emacs.sh | 102 | ||||
-rw-r--r-- | .config/bash/rc.sh | 65 | ||||
-rw-r--r-- | .config/emacs/init.el | 26 |
10 files changed, 193 insertions, 174 deletions
diff --git a/.config/bash/rc.d/01_unset_prompt_command.sh b/.config/bash/rc.d/01_unset_prompt_command.sh new file mode 100644 index 0000000..165fdbc --- /dev/null +++ b/.config/bash/rc.d/01_unset_prompt_command.sh @@ -0,0 +1,3 @@ +#!/hint/bash + +PROMPT_COMMAND='' diff --git a/.config/bash/rc.d/aliases.sh b/.config/bash/rc.d/10_aliases.sh index cd2cfd8..758c069 100644 --- a/.config/bash/rc.d/aliases.sh +++ b/.config/bash/rc.d/10_aliases.sh @@ -1,7 +1,7 @@ #!/hint/bash ###################################################################### -# Set up colors and settings for ls/dir/vdir # +# Set up colors and settings for all the things # ###################################################################### if [ -x "`which dircolors`" ]; then eval "$(dircolors -p | cat - "${XDG_CONFIG_HOME}/dir_colors" | @@ -12,12 +12,40 @@ if [ -x "`which dircolors`" ]; then for xgrep in ${PATH//:/\/*grep }/*grep; do if [ -f "$xgrep" ]; then - xgrep=`basename "$xgrep"` + xgrep=$(basename "$xgrep") if [ "$xgrep" != pgrep ]; then alias $xgrep="$xgrep --color=auto" fi fi done + unset xgrep + + wdiff() { + if [[ -t 1 ]]; then + local red="$(tput setaf 1)" + local blue="$(tput setaf 4)" + local bold="$(tput bold)" + local reset="$(tput sgr0)" + command wdiff \ + -w "$bold$red[-" \ + -x "-]$reset" \ + -y "$bold$blue{+" \ + -z "+}$reset" "$@" + else + command wdiff "$@" + fi + } + + diff() { + if [[ -t 1 ]]; then + ( + set -o pipefail + command diff "$@" | colordiff + ) + else + command diff "$@" + fi + } else alias ls='ls -1v' alias dir='dir -v' @@ -35,17 +63,23 @@ alias l='ls -CF' # Some preferences for miscellaneous stuff # ###################################################################### #alias rm='gvfs-trash' -#alias sed='sed --follow-symlinks' # breaks sed 4.2.2 +#alias sed='sed --follow-symlinks' # breaks operating on stdio in GNU sed 4.2.2 alias tree='tree --charset utf8' alias cd=pushd alias gitk='gitk --all --date-order' alias userctl='systemctl --user' ###################################################################### -# Some almost-function aliases # +# These are actually functions :P # ###################################################################### -alias lock="clear; away -C 'This terminal is locked'" -alias plock="term-title Terminal Locked;lock" +term-title() { + local fmt='' + case "$TERM" in + screen|tmux) fmt='\ek%s\e\\';; + xterm*|rxvt*) fmt='\e]0;%s\a';; + esac + printf "$fmt" "$*" +} mvln() { if [[ ! -L "$1" ]]; then libremessages error 'Not a soft link: %s' "$1" @@ -58,6 +92,20 @@ mvln() { libremessages error 'Failed moving link: %s -> %s' "$1" "$2" fi } -jarls() { jar tf "$1" | sed -n 's/\.class$//p' | LC_ALL=C sort | xargs -r -d $'\n' javap -classpath "$1"; } -tarls() { local file; for file in "$@"; do bsdtar tf "$file" | sed "s|^|$file:|"; done; } -jarmain() { jarls "$1" 2>/dev/null | grep -E '(^[a-z]|public static void main\(java\.lang\.String\[\]\))' | grep -B1 '^ '; } +jarls() { + jar tf "$1" | + sed -n 's/\.class$//p' | + LC_ALL=C sort | + xargs -r -d $'\n' javap -classpath "$1" +} +tarls() { + local file + for file in "$@"; do + bsdtar tf "$file" | sed "s|^|$file:|" + done +} +jarmain() { + jarls "$1" 2>/dev/null | + grep -E '(^[a-z]|public static void main\(java\.lang\.String\[\]\))' | + grep -B1 '^ ' +} diff --git a/.config/bash/rc.d/10_hist.sh b/.config/bash/rc.d/10_hist.sh new file mode 100644 index 0000000..d7c6bfc --- /dev/null +++ b/.config/bash/rc.d/10_hist.sh @@ -0,0 +1,9 @@ +#!/hint/bash + +# don't overwrite GNU Midnight Commander's setting of `ignorespace'. +HISTCONTROL=$HISTCONTROL${HISTCONTROL+,}ignoredups +HISTFILE=${XDG_CACHE_HOME}/bash/history +HISTTIMEFORMAT='[%Y-%m-%d %H:%M] ' +HISTSIZE=5000 +shopt -s histappend # append to the history file, don't overwrite it +mkdir -p "${HISTFILE%/*}" diff --git a/.config/bash/rc.d/10_misc.sh b/.config/bash/rc.d/10_misc.sh new file mode 100644 index 0000000..afcf6fd --- /dev/null +++ b/.config/bash/rc.d/10_misc.sh @@ -0,0 +1,10 @@ +#!/hint/bash + +# General settings +shopt -s checkwinsize # update the values of LINES and COLUMNS +shopt -s globstar # Let ** recursively scan directories + +# Why is this not on by default? +# "We have a cached value, but it isn't valid anymore. Should we trash it?" +# "Duh, yes!" +shopt -s checkhash diff --git a/.config/bash/rc.d/90_emacs.sh b/.config/bash/rc.d/90_emacs.sh new file mode 100644 index 0000000..595ddcf --- /dev/null +++ b/.config/bash/rc.d/90_emacs.sh @@ -0,0 +1,63 @@ +#!/hint/bash + +if [[ $TERM == eterm* ]]; then + ## Primatives for interacting with Emacs ############################### + + # _emacs_run LISP + _emacs_run() { + emacsclient -a false -e "$*" 2>/dev/null + } + # _emacs_quote UNQUOTED_STRING + _emacs_quote() { + local str="$*" + str="${str//\\/\\\\}" # \ -> \\ + str="${str//\"/\\\"}" # " -> \" + str="\"${str}\"" # wrap it in quotes + printf '%s' "$str" + } + # _emacs_unquote QUOTED_STRING + _emacs_unquote() { + local str="$*" + if [[ $str =~ ^\"(.*)\"$ ]]; then + str=${BASH_REMATCH[1]} # un-quote it + str="${str//\\\\/\\}" # \\ -> \ + str="${str//\\\"/\"}" # \" -> " + fi + printf '%s' "$str" + } + + ## High-level tasks #################################################### + + # Set the TRAMP directory for remote hosts (shell -> emacs) + _emacs_set_remote_dir() { + # Because (term-handle-ansi-terminal-messages) is run + # after each item is set, the user should be set + # before the hostname is set, otherwise it will set + # (default-directory) to an invalid TRAMP string. + # + # Because the hostname is compared to (system-name) to + # check if it is localhost, "$(hostname -f)" needs to + # be used instead of $HOSTNAME, unfortunately. + printf '\eAnSiT%s %s\n' \ + u "$USER" \ + c "$PWD" \ + h "$(hostname -f)" + } + # Set the shell's X11 display (emacs -> shell) + _emacs_set_shell_DISPLAY() { + export DISPLAY=$(_emacs_unquote "$(_emacs_run "(cdr (assoc 'display (frame-parameters)))")") + [[ $DISPLAY != nil ]] || unset DISPLAY + } + + ## Install the hooks ################################################### + + export SELECTED_EDITOR='emacsclient' + export EDITOR=$SELECTED_EDITOR + export VISUAL=$SELECTED_EDITOR + export PAGER=cat + if _emacs_run '()' >/dev/null; then + PROMPT_COMMAND+='_emacs_set_shell_DISPLAY;' + fi + # Remember, the $() strips the trailing newline, so add it back in + PS1_EXTRA+='\[$(_emacs_set_remote_dir)'$'\n\\]' +fi diff --git a/.config/bash/rc.d/90_term_title.sh b/.config/bash/rc.d/90_term_title.sh new file mode 100644 index 0000000..d39d8b0 --- /dev/null +++ b/.config/bash/rc.d/90_term_title.sh @@ -0,0 +1,3 @@ +#!/hint/bash + +PS1_EXTRA+="\\[$(term-title '\u@\h:\w')\\]" diff --git a/.config/bash/rc.d/99_ps1.sh b/.config/bash/rc.d/99_ps1.sh new file mode 100644 index 0000000..450e118 --- /dev/null +++ b/.config/bash/rc.d/99_ps1.sh @@ -0,0 +1,20 @@ +#!/hint/bash + +if 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 such + # a case would tend to support setf rather than setaf.) + RESET="\\[$(tput sgr0)\\]" + BOLD="\\[$(tput bold)\\]" + RED="\\[$(tput setaf 1)\\]" + GREEN="\\[$(tput setaf 2)\\]" + BLUE="\\[$(tput setaf 4)\\]" + + STATUS="${BOLD}[" + STATUS+="\$(v=\$?; [[ \$v = 0 ]] && c='${GREEN}' || c='${RED}'; printf %s%03i \$c \$v)" + STATUS+="${RESET}${BOLD}]${RESET}" +else + STATUS='[$(printf "%03i" $?)]' +fi +PS1="${STATUS} ${BOLD}${GREEN}\u@\h${BLUE}:\w${RESET}${PS1_EXTRA}\\n\\$ " +unset RESET BOLD RED GREEN BLUE STATUS PS1_EXTRA diff --git a/.config/bash/rc.d/emacs.sh b/.config/bash/rc.d/emacs.sh deleted file mode 100644 index d8e1d80..0000000 --- a/.config/bash/rc.d/emacs.sh +++ /dev/null @@ -1,102 +0,0 @@ -#!/hint/bash - -if [[ $TERM == eterm* ]]; then - SELECTED_EDITOR='emacsclient' - EDITOR=$SELECTED_EDITOR - VISUAL=$SELECTED_EDITOR - export SELECTED_EDITOR EDITOR VISUAL - export PAGER=cat - - ## Primatives for interacting with Emacs ############################### - - # _emacs_run LISP - _emacs_run() { - emacsclient -a false -e "$*" 2>/dev/null - } - # _emacs_quote UNQUOTED_STRING - _emacs_quote() { - local str="$*" - str="${str//\\/\\\\}" # \ -> \\ - str="${str//\"/\\\"}" # " -> \" - str="\"${str}\"" # wrap it in quotes - printf '%s' "$str" - } - # _emacs_unquote QUOTED_STRING - _emacs_unquote() { - - local str="$*" - if [[ $str =~ ^\"(.*)\"$ ]]; then - str=${BASH_REMATCH[1]} # un-quote it - str="${str//\\\\/\\}" # \\ -> \ - str="${str//\\\"/\"}" # \" -> " - fi - printf '%s' "$str" - } - - ## Deal with renaming the terminal ##################################### - - # _emacs_rename_terminal NEW_BUFFER_NAME - # This function uses the variable _EMACS_BUFFER to store some state - _emacs_rename_terminal() { - local name=$(_emacs_quote "$*") - if [[ -n $_EMACS_BUFFER ]]; then - local buffer="(get-buffer $_EMACS_BUFFER)" - else - local buffer='(window-buffer (selected-window))' - fi - _EMACS_BUFFER=$(_emacs_run "(with-current-buffer ${buffer} (rename-buffer ${name} t))") - } - # _emacs_get_short_cwd - _emacs_get_short_cwd() { - local base=$PWD - local suffix='' - # The regex here is a list of directory names - # that aren't really helpful, and that the - # parent directory should be included also. - if [[ $base =~ (/(src|pkg|doc|pkg-libre|src-libre|trunk|tags|branches))*$ ]]; then - suffix=$BASH_REMATCH - base=${base%$suffix} - fi - base=${base##*/} - echo ${base}${suffix} - } - # _emacs_get_desired_buffer_name - _emacs_get_desired_buffer_name() { - echo "*ansi-term*<$(_emacs_get_short_cwd)>" - } - - ## High-level tasks #################################################### - - # Like uniquify on the buffer name (shell -> emacs) - _emacs_set_buffer_name() { - # This doesn't work correctly on remote hosts. - # The "correct" solution is probably to hook into - # default-directory being set in term.el - _emacs_rename_terminal "$(_emacs_get_desired_buffer_name)" - } - # Set the TRAMP directory for remote hosts (shell -> emacs) - _emacs_set_remote_dir() { - if [[ -n $SSH_CONNECTION ]]; then - printf '\eAnSiT%s %s\n' \ - u "$USER" \ - c "$PWD" \ - h "$HOSTNAME" - fi - } - # Set the shell's X11 display (emacs -> shell) - _emacs_set_shell_DISPLAY() { - export DISPLAY=$(_emacs_unquote "$(_emacs_run "(cdr (assoc 'display (frame-parameters)))")") - [[ $DISPLAY != nil ]] || unset DISPLAY - } - - ## Do those things ##################################################### - - _emacs_PROMPT_COMMAND() { - _emacs_set_buffer_name - _emacs_set_remote_dir - _emacs_set_shell_DISPLAY - } - if _emacs_run '()' >/dev/null; then - PROMPT_COMMAND=_emacs_PROMPT_COMMAND - fi -fi diff --git a/.config/bash/rc.sh b/.config/bash/rc.sh index 70f1ce4..8512d84 100644 --- a/.config/bash/rc.sh +++ b/.config/bash/rc.sh @@ -5,74 +5,13 @@ # they are login shells or not. # If not running interactively, don't do anything -[[ $- != *i* ]] && return +# This line is probably not nescessary, but whatevs. +[[ $- == *i* ]] || return # GDM failsafe ignores profile (login) settings, but I use XDG stuff # here. . "${XDG_CONFIG_HOME:-$HOME/.config}"/login.d/??_xdg.sh -# Why is this not on by default? -# "We have a cached value, but it isn't valid anymore. Should we trash it?" -# "Duh, yes!" -shopt -s checkhash - -################################################################################ - -# History settings -# don't overwrite GNU Midnight Commander's setting of `ignorespace'. -HISTCONTROL=$HISTCONTROL${HISTCONTROL+,}ignoredups -HISTFILE=${XDG_CACHE_HOME}/bash/history -HISTTIMEFORMAT='[%Y-%m-%d %H:%M] ' -HISTSIZE=5000 -shopt -s histappend # append to the history file, don't overwrite it -mkdir -p "${HISTFILE%/*}" - -# General settings -shopt -s checkwinsize # update the values of LINES and COLUMNS -shopt -s globstar # Let ** recursively scan directories - -################################################################################ -# Overly complicated setting of PS1 # -################################################################################ - -# Belongs in aliases, but I use it here -term-title() { - local fmt='' - case "$TERM" in - screen|tmux) fmt='\ek%s\e\\';; - xterm*|rxvt*) fmt='\e]0;%s\a';; - esac - printf "$fmt" "$*" -} -PROMPT_COMMAND='' - -make_prompt() { - echo "${BOLD}${GREEN}\u@\h${BLUE}:\w${RESET}" -} - -if 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 such - # a case would tend to support setf rather than setaf.) - RESET="$(tput sgr0)" - BOLD="$(tput bold)" - RED="$(tput setaf 1)" - GREEN="$(tput setaf 2)" - BLUE="$(tput setaf 4)" - - _STATUS="${BOLD}[" - _STATUS+="\$(v=\$?; [[ \$v = 0 ]] && c='${GREEN}' || c='${RED}'; printf %s%03i \$c \$v)" - _STATUS+="${RESET}${BOLD}]${RESET}" -else - _STATUS='[$(printf "%03i" $?)]' -fi -PS1="${_STATUS} $(make_prompt)"'\n\$ ' -unset RESET BOLD RED GREEN BLUE _STATUS -PS1="$(term-title $(make_prompt))$PS1" -unset make_prompt - -################################################################################ - # Include modular config files if [[ -d ${XDG_CONFIG_HOME}/bash/rc.d ]]; then for file in "${XDG_CONFIG_HOME}/bash/rc.d"/*.sh; do diff --git a/.config/emacs/init.el b/.config/emacs/init.el index e635b77..90fda1b 100644 --- a/.config/emacs/init.el +++ b/.config/emacs/init.el @@ -161,6 +161,32 @@ sh-script.el is broken." (advice-add 'sh-smie-sh-rules :filter-args #'sh-smie-sh-rules--fix) +;; Ideally, figuring this out should be done by uniquify, but I +;; haven't determined how to get uniquify to think that it manages the +;; term buffer. +(defun term-get-short-cwd () + ;; local base=$PWD + ;; local suffix='' + ;; # The regex here is a list of directory names + ;; # that aren't really helpful, and that the + ;; # parent directory should be included also. + ;; if [[ $base =~ (/(src|pkg|doc|pkg-libre|src-libre|trunk|tags|branches))*$ ]]; then + ;; suffix=$BASH_REMATCH + ;; base=${base%$suffix} + ;; fi + ;; base=${base##*/} + ;; echo ${base}${suffix} + (directory-file-name default-directory)) +(defun term-handle-ansi-terminal-messages--uniquify (args) + (rename-buffer (concat + (replace-regexp-in-string "<.*>$" "" (buffer-name)) + "<" + (term-get-short-cwd) + ">") + t)) +(advice-add 'term-handle-ansi-terminal-messages :after + #'term-handle-ansi-terminal-messages--uniquify) + (require 'go-mode-load nil t) |