blob: 41542e2d35aa88e23bece9b4e21a5430022bd08e (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
|
# Source global definitions
if [ -f /etc/bashrc ]; then
source /etc/bashrc
fi
# If not running interactively, don't do anything
[[ $- != *i* ]] && return
# Set umask to allow only the user to write or execute new files
# https://en.wikipedia.org/wiki/Umask
umask 033
# Simple helper to add directory to $PATH if they are not included yet
pathadd() {
if [ -d "$1" ] && [[ "$PATH" != *"$1"* ]]; then
PATH="$1":$PATH
fi
}
pathadd "${HOME}"/.local/bin
source "${HOME}"/.aliases
# navigate to first parent directory matching a regex
upto() {
if [ -z "$1" ]; then
echo 'Usage: upto <pattern>' >&2
return 1
fi
local upto="$1"
cd "${PWD/\/$upto\/*//$upto}" || return
}
# Rather simple prompt inspired by:
# https://code.mendhak.com/simple-bash-prompt-for-developers-ps1-git/
# Our prompt should show the user and the hostname because the uberspace
# connection is always a remote connection to different hosts.
# Having the user and the host in the prompt allows a better overview where
# we actually are.
# Also git information should be presented if available.
# Source git-prompt code to have the git prompt helpers available
# Found via: `locate git-prompt`
source /usr/share/git-core/contrib/completion/git-prompt.sh
__prompt() {
# This must be the first thing done to not override the last exit code
local last_status=$?
local -r RESET='\[\033[00m\]'
local -r RED='\[\033[31m\]'
local -r GREEN='\[\033[32m\]'
local -r YELLOW='\[\033[33m\]'
if [[ "$last_status" -gt 0 ]]; then
last_status=" ${RED}""${last_status}"
else
last_status=""
fi
PS1="\u@\h ${GREEN}\W${YELLOW}$(GIT_PS1_SHOWUNTRACKEDFILES=1 GIT_PS1_SHOWDIRTYSTATE=1 __git_ps1)${last_status}${RESET}\$ "
}
PROMPT_COMMAND=(__prompt)
# Sensible Bash - An attempt at saner Bash defaults
# Maintainer: mrzool <http://mrzool.cc>
# Repository: https://github.com/mrzool/bash-sensible
# Version: 0.2.2
# Unique Bash version check
if ((BASH_VERSINFO[0] < 4))
then
echo "sensible.bash: Looks like you're running an older version of Bash."
echo "sensible.bash: You need at least bash-4.0 or some options will not work correctly."
echo "sensible.bash: Keep your software up-to-date!"
fi
## GENERAL OPTIONS ##
# Prevent file overwrite on stdout redirection
# Use `>|` to force redirection to an existing file
set -o noclobber
# Update window size after every command
shopt -s checkwinsize
# Automatically trim long paths in the prompt (requires Bash 4.x)
PROMPT_DIRTRIM=2
# Enable history expansion with space
# E.g. typing !!<space> will replace the !! with your last command
bind Space:magic-space
# Turn on recursive globbing (enables ** to recurse all directories)
shopt -s globstar 2> /dev/null
# Case-insensitive globbing (used in pathname expansion)
shopt -s nocaseglob;
## SMARTER TAB-COMPLETION (Readline bindings) ##
# Perform file completion in a case insensitive fashion
bind "set completion-ignore-case on"
# Treat hyphens and underscores as equivalent
bind "set completion-map-case on"
# Display matches for ambiguous patterns at first tab press
bind "set show-all-if-ambiguous on"
# Immediately add a trailing slash when autocompleting symlinks to directories
bind "set mark-symlinked-directories on"
## SANE HISTORY DEFAULTS ##
# Append to the history file, don't overwrite it
shopt -s histappend
# Save multi-line commands as one command
shopt -s cmdhist
# Record each line as it gets issued
PROMPT_COMMAND+=('history -a')
# Huge history. Doesn't appear to slow things down, so why not?
HISTSIZE=500000
HISTFILESIZE=100000
# Avoid duplicate entries
HISTCONTROL="erasedups:ignoreboth"
# Don't record some commands
export HISTIGNORE="&:[ ]*:exit:ls:bg:fg:history:clear"
# Use standard ISO 8601 timestamp
# %F equivalent to %Y-%m-%d
# %T equivalent to %H:%M:%S (24-hours format)
HISTTIMEFORMAT='%F %T '
# Enable incremental history search with up/down arrows (also Readline goodness)
# Learn more about this here: http://codeinthehole.com/writing/the-most-important-command-line-tip-incremental-history-searching-with-inputrc/
bind '"\e[A": history-search-backward'
bind '"\e[B": history-search-forward'
bind '"\e[C": forward-char'
bind '"\e[D": backward-char'
## BETTER DIRECTORY NAVIGATION ##
# Prepend cd to directory names automatically
shopt -s autocd 2> /dev/null
# Correct spelling errors during tab-completion
shopt -s dirspell 2> /dev/null
# Correct spelling errors in arguments supplied to cd
shopt -s cdspell 2> /dev/null
|