-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdot_bashrc.tmpl
More file actions
119 lines (100 loc) · 3.95 KB
/
Copy pathdot_bashrc.tmpl
File metadata and controls
119 lines (100 loc) · 3.95 KB
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
#!/usr/bin/env bash
# shellcheck disable=SC1054,SC1083,SC1009,SC1073,SC1065,SC1064,SC1072 # Contains Go template syntax
# PATH and environment (shared with login and non-interactive shells).
# Kept above the interactive guard: bash sources ~/.bashrc (not $BASH_ENV)
# for an sshd-spawned non-interactive command, so one-shot `ssh host cmd`
# only picks this up if it runs before the guard returns.
# shellcheck disable=SC1090,SC1091
[ -f "${HOME}/.bash_env" ] && . "${HOME}/.bash_env"
# If not running interactively, don't do anything
case $- in
*i*) ;;
*) return ;;
esac
# don't put duplicate lines or lines starting with space in the history.
# See bash(1) for more options
HISTCONTROL=ignoreboth
# append to the history file, don't overwrite it
shopt -s histappend
# for setting history length see HISTSIZE and HISTFILESIZE in bash(1)
HISTSIZE=10000
HISTFILESIZE=20000
# check the window size after each command and, if necessary,
# update the values of LINES and COLUMNS.
shopt -s checkwinsize
set -o vi
set -o ignoreeof
set -o noclobber
# make less more friendly for non-text input files, see lesspipe(1)
[ -x /usr/bin/lesspipe ] && eval "$(SHELL=/bin/sh lesspipe)"
# Alias definitions.
# You may want to put all your additions into a separate file like
# ~/.bash_aliases, instead of adding them here directly.
# See /usr/share/doc/bash-doc/examples in the bash-doc package.
if [ -f ~/.bash_aliases ]; then
# shellcheck disable=SC1090,SC1091
. ~/.bash_aliases
fi
# enable programmable completion features (you don't need to enable
# this, if it's already enabled in /etc/bash.bashrc and /etc/profile
# sources /etc/bash.bashrc).
if ! shopt -oq posix; then
# shellcheck disable=SC1090,SC1091
if [ -f /usr/share/bash-completion/bash_completion ]; then
. /usr/share/bash-completion/bash_completion
elif [ -f /etc/bash_completion ]; then
. /etc/bash_completion
fi
fi
{{ if eq .chezmoi.os "darwin" -}}
(command -v brew >/dev/null) && {
HOMEBREW_PREFIX="$(brew --prefix)"
if [[ -r "${HOMEBREW_PREFIX}/etc/profile.d/bash_completion.sh" ]]; then
# shellcheck disable=SC1091
source "${HOMEBREW_PREFIX}/etc/profile.d/bash_completion.sh"
else
for COMPLETION in "${HOMEBREW_PREFIX}/etc/bash_completion.d/"*; do
# shellcheck disable=SC1090
[[ -r "$COMPLETION" ]] && source "$COMPLETION"
done
fi
}
{{ end -}}
if [ -f ~/.bash_prompt ]; then
# shellcheck disable=SC1090,SC1091
. ~/.bash_prompt
fi
# shellcheck disable=SC1090
[ -f "${HOME}/.local.bashrc" ] && source "${HOME}/.local.bashrc"
function start_ssh_agent() {
# shellcheck disable=SC1090,SC1091
(command -v ssh-agent >/dev/null 2>&1) && {
if command -v keychain >/dev/null 2>&1; then {
find "${HOME}/.ssh" -maxdepth 1 -name 'id_*' ! -name '*.pub' -print0 | xargs -0 keychain -q
source "${HOME}/.keychain/${HOSTNAME}-sh"
}; else
{
# Use flock to prevent race conditions when multiple shells start simultaneously
local lockfile="${HOME}/.ssh/agent.lock"
(
# Skip locking where flock is unavailable (e.g. macOS without
# util-linux); the agent still starts, just without race protection.
if command -v flock >/dev/null 2>&1; then
flock -n 200 || exit 0
fi
[ -f "${HOME}/.ssh/agent.pid" ] && source "${HOME}/.ssh/agent.pid" >/dev/null 2>&1
if [ -z "${SSH_AGENT_PID}" ] || ! ps -p "${SSH_AGENT_PID}" >/dev/null 2>&1; then
echo "cleanup and restart ssh-agent" >&2
[ -f "${HOME}/.ssh/agent.pid" ] && rm -f "${HOME}/.ssh/agent.pid"
ssh-agent >"${HOME}/.ssh/agent.pid"
fi
) 200>>"${lockfile}"
# Source the agent file outside the lock
[ -f "${HOME}/.ssh/agent.pid" ] && source "${HOME}/.ssh/agent.pid" >/dev/null 2>&1
}
fi
}
}
[ ! -f "{{ .chezmoi.homeDir }}/.ssh/noagent" ] && start_ssh_agent || true
# according to man page should be near end of bashrc
(command -v direnv >/dev/null 2>&1) && eval "$(direnv hook bash)"