aboutsummaryrefslogtreecommitdiff
path: root/bash
diff options
context:
space:
mode:
Diffstat (limited to 'bash')
-rw-r--r--bash/bash_completion.d/_ssh_config_hosts.bash29
-rw-r--r--bash/bash_completion.d/keep.bash2
-rw-r--r--bash/bash_completion.d/mosh.bash5
-rw-r--r--bash/bash_completion.d/path.bash1
-rw-r--r--bash/bash_profile7
-rw-r--r--bash/bashrc4
-rw-r--r--bash/bashrc.d/keep.bash8
-rw-r--r--bash/bashrc.d/prompt.bash34
8 files changed, 63 insertions, 27 deletions
diff --git a/bash/bash_completion.d/_ssh_config_hosts.bash b/bash/bash_completion.d/_ssh_config_hosts.bash
index 0959f52b..16265e8a 100644
--- a/bash/bash_completion.d/_ssh_config_hosts.bash
+++ b/bash/bash_completion.d/_ssh_config_hosts.bash
@@ -3,23 +3,28 @@ _ssh_config_hosts() {
# Iterate through SSH client config paths
local config
- for config in "$HOME"/.ssh/config /etc/ssh/ssh_config ; do
+ for config in /etc/ssh/ssh_config.d/*.conf /etc/ssh/ssh_config \
+ "$HOME"/.ssh/config.d/*.conf "$HOME"/.ssh/config ; do
[[ -e $config ]] || continue
- # Read 'Host' options and their first value from file
- local option value ci
- while read -r option value _ ; do
+ # Read 'Host' options and their patterns from file
+ local option value patterns pattern ci
+ while read -r option value ; do
[[ $option == Host ]] || continue
+ read -a patterns -r \
+ < <(printf '%s\n' "$value")
# Check host value
- case $value in
- # No empties
- '') ;;
- # No wildcards
- *'*'*) ;;
- # Found a match; print it
- "$2"*) COMPREPLY[ci++]=$value ;;
- esac
+ for pattern in "${patterns[@]}" ; do
+ case $pattern in
+ # No empties
+ '') ;;
+ # No wildcards
+ *'*'*) ;;
+ # Found a match; print it
+ "$2"*) COMPREPLY[ci++]=$pattern ;;
+ esac
+ done
done < "$config"
done
diff --git a/bash/bash_completion.d/keep.bash b/bash/bash_completion.d/keep.bash
index 4b479eca..8bb4615f 100644
--- a/bash/bash_completion.d/keep.bash
+++ b/bash/bash_completion.d/keep.bash
@@ -44,7 +44,7 @@ _keep() {
fi
# Build list of kept names
- bashkeep=${BASHKEEP:-"$HOME"/.bashkeep.d}
+ bashkeep=${XDG_DATA_HOME:-"$HOME"/.local/share}/bashkeep
for keep in "$bashkeep"/"$2"*.bash ; do
# Skip directories
! [[ -d $keep ]] || continue
diff --git a/bash/bash_completion.d/mosh.bash b/bash/bash_completion.d/mosh.bash
new file mode 100644
index 00000000..17d72ca1
--- /dev/null
+++ b/bash/bash_completion.d/mosh.bash
@@ -0,0 +1,5 @@
+# Completion for mosh(1) with ssh_config(5) hostnames
+if ! declare -F _ssh_config_hosts >/dev/null ; then
+ source "$HOME"/.bash_completion.d/_ssh_config_hosts.bash
+fi
+complete -F _ssh_config_hosts -o bashdefault -o default mosh
diff --git a/bash/bash_completion.d/path.bash b/bash/bash_completion.d/path.bash
index 9224506a..9234f132 100644
--- a/bash/bash_completion.d/path.bash
+++ b/bash/bash_completion.d/path.bash
@@ -62,6 +62,7 @@ _path() {
fi
# Break PATH into parts
+ declare -a paths
IFS=: read -a paths -d '' -r \
< <(printf '%s\0' "$PATH")
diff --git a/bash/bash_profile b/bash/bash_profile
index 1f5a633a..2f3ba81f 100644
--- a/bash/bash_profile
+++ b/bash/bash_profile
@@ -10,6 +10,13 @@ if [ -n "$POSIXLY_CORRECT" ] ; then
return
fi
+# Load any supplementary scripts in ~/.bash_profile.d; it need not exist
+for bash in "$HOME"/.bash_profile.d/*.bash ; do
+ [ -e "$bash" ] || continue
+ . "$bash"
+done
+unset -v bash
+
# If ~/.bashrc exists, source that too; the tests for both interactivity and
# minimum version numbers are in there
if [ -f "$HOME"/.bashrc ] ; then
diff --git a/bash/bashrc b/bash/bashrc
index 6e4c31a9..5d3a7bbc 100644
--- a/bash/bashrc
+++ b/bash/bashrc
@@ -28,8 +28,8 @@ fi
# Clear away command_not_found_handle if a system bashrc file set it up
unset -f command_not_found_handle
-# Keep around 32K lines of history in file
-HISTFILESIZE=$((1 << 15))
+# Keep around 128K lines of history in file
+HISTFILESIZE=131072
# Ignore duplicate commands
HISTCONTROL=ignoredups
diff --git a/bash/bashrc.d/keep.bash b/bash/bashrc.d/keep.bash
index 6796aae7..26a84f5b 100644
--- a/bash/bashrc.d/keep.bash
+++ b/bash/bashrc.d/keep.bash
@@ -29,7 +29,7 @@ keep() {
# Figure out the directory to which we're reading and writing these scripts
local bashkeep
- bashkeep=${BASHKEEP:-"$HOME"/.bashkeep.d}
+ bashkeep=${XDG_DATA_HOME:-"$HOME"/.local/share}/bashkeep
mkdir -p -- "$bashkeep" || return
# Parse options
@@ -89,8 +89,8 @@ EOF
case $name in
# NAME must start with letters or an underscore, and contain no
- # characters besides letters, numbers, or underscores
- *[!a-zA-Z0-9_]*|[!a-zA-Z_]*)
+ # characters besides letters, numbers, underscores, or dashes
+ [!a-zA-Z_]*|*[!a-zA-Z0-9_-]*)
printf 'bash: %s: %s not a valid NAME\n' \
"${FUNCNAME[0]}" "$name" >&2
((errors++))
@@ -140,7 +140,7 @@ EOF
}
# Load any existing scripts in bashkeep
-for bashkeep in "${BASHKEEP:-"$HOME"/.bashkeep.d}"/*.bash ; do
+for bashkeep in "${XDG_DATA_HOME:-"$HOME"/.local/share}"/bashkeep/*.bash ; do
[[ -e $bashkeep ]] || continue
source "$bashkeep"
done
diff --git a/bash/bashrc.d/prompt.bash b/bash/bashrc.d/prompt.bash
index f9678f20..e0a03438 100644
--- a/bash/bashrc.d/prompt.bash
+++ b/bash/bashrc.d/prompt.bash
@@ -7,29 +7,32 @@ prompt() {
# Turn complex, colored PS1 and debugging PS4 prompts on
on)
# Set up pre-prompt command
- PROMPT_COMMAND='history -a'
+ PROMPT_COMMAND='PROMPT_RETURN=$?;history -a'
# If Bash 4.0 is available, trim very long paths in prompt
if ((BASH_VERSINFO[0] >= 4)) ; then
PROMPT_DIRTRIM=4
fi
- # Basic prompt shape depends on whether we're in SSH or not
+ # Prompt has hostname via SSH outside of screen/tmux
PS1=
- if [[ -n $SSH_CLIENT || -n $SSH_CONNECTION ]] ; then
+ if [[ -n $SSH_CLIENT && -z $STY && -z $TMUX ]] ; then
PS1=$PS1'\h:'
fi
PS1=$PS1'\w'
- # Add sub-commands; VCS, job, and return status checks
- PS1=$PS1'$(ret=$?;prompt vcs;prompt job;prompt ret)'
-
# Add a helpful prefix if this shell appears to be exotic
case ${SHELL##*/} in
(bash) ;;
(*) PS1=bash:$PS1 ;;
esac
+ # Add sub-commands:
+ ## Preload libraries as prefix
+ PS1='$(prompt preload)'$PS1
+ ## VCS, job, and return status checks as suffixes
+ PS1=$PS1'$(prompt vcs;prompt job;prompt ret)'
+
# Add prefix and suffix
PS1='${PROMPT_PREFIX}'$PS1'${PROMPT_SUFFIX}'
@@ -92,6 +95,21 @@ prompt() {
fi
;;
+ # Analyze LD_PRELOAD to see if we should report anything loaded
+ preload)
+ printf '%s:' "$LD_PRELOAD" |
+ while read -d : -r ; do
+ case $REPLY in
+ (*/libip2unix.so)
+ printf '[IP2Unix]'
+ ;;
+ (*/libtorsocks.so)
+ printf '[Tor]'
+ ;;
+ esac
+ done
+ ;;
+
# Git prompt function
git)
@@ -249,8 +267,8 @@ prompt() {
# Show return status of previous command in angle brackets, if not zero
ret)
# shellcheck disable=SC2154
- ((ret)) || return
- printf '<%u>' "${ret//\\/\\\\}"
+ ((PROMPT_RETURN)) || return
+ printf '<%u>' "${PROMPT_RETURN//\\/\\\\}"
;;
# Show the count of background jobs in curly brackets, if not zero