Repository navigation
Expand file tree
/
Copy path.bashrc
More file actions
183 lines (155 loc) · 5.46 KB
/
Copy path.bashrc
File metadata and controls
183 lines (155 loc) · 5.46 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
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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
# -*- mode: sh; sh-shell: bash -*-
## bash -n .bashrc
## shellcheck .bashrc
#### home-bash-configuration -> .bashrc_additions: begin
# --- GnuPG / direnv setup ---
# See `info "(gnupg) Invoking GPG-AGENT"`
export GPG_TTY=$(tty)
# Export empty DIRENV_LOG_FORMAT to silence direnv log output. See
# https://github.com/direnv/direnv/issues/68
#
# CAVEAT: this hides direnv's "is blocked"/"is denied" errors. See
# `direnv status` (look for "Found RC allowed 2" = denied) and fix with
# `direnv allow ~`
export DIRENV_LOG_FORMAT=
eval "$(direnv hook bash)"
# --- History & shell options for convenience ---
shopt -s autocd # Type just a directory name to cd into it
shopt -s cdspell # Fixe small typos in cd paths
shopt -s checkwinsize # Update $LINES/$COLUMNS when resizing terminal
HISTCONTROL=ignoredups:erasedups # Avoid clutter in history
# Enlarge history beyond defaults
HISTSIZE=100000
HISTFILESIZE=200000
# --- Functions ---
# In Bash, a script runs in a subshell, so `cd` only changes the directory
# within that subshell. To change the state of the current shell (such as the
# working directory with `cd`), the logic must be implemented as a shell
# function.
# $* vs. $@
# "$*" concatenates all args into a single string, separated by the first
# character of $IFS (normally a space)
# "$@" treats each arg as its own word.
# -- is a POSIX‑style "end of options" marker
# Clone with gicl (Scheme procedure) and cd into the resulting directory.
# `command' bypasses this very function so it doesn't recurse; `gicl' only
# prints the cloned directory on stdout, on success -- see
# guix/home/common/scm-bin/git-clone.scm for why (a subprocess can't change its
# parent shell's directory, so the cd has to happen out here).
gicl() {
local dir
dir=$(command gicl -- "$@") || return
cd -- "$dir" || return
}
# mkdir + cd
mkcd() {
mkdir -p -- "$*" || return
cd -- "$*" || return
}
# alias for mkcd
take() { mkcd "$@"; }
# Shortcuts for moving up dirs
..() { cd ..; }
...() { cd ../..; }
....() { cd ../../..; }
# Directory shortcuts. ${VARNAME:?} guards against unset VARNAME
bin() { cd "$HOME/bin"; }
cheat() { cd "${cheat:?}"; }
corona() { cd "${dec:?}/corona_cases"; }
dec() { cd "${dec:?}"; }
dema() { cd "${dev:?}/emacs"; }
der() { cd "${der:?}"; }
desk() { cd ~/Desktop; }
dev() { cd "${dev:?}"; }
dgl() { cd "${dgl:?}"; }
dgx() { cd "${dgx:?}"; }
dngx() { cd "${dngx:?}"; }
dbstx() { cd "${dbstx:?}"; }
dotf() { cd "${dotf:?}"; }
down() { cd ~/Downloads; }
dspd() { cd "${dspd:?}"; }
dspg() { cd "${dspg:?}"; }
dspc() { cd "${dspc:?}"; }
dsps() { cd "${dsps:?}"; }
dtf() { cd "${dtf:?}"; }
dtfg() { cd "${dtfg:?}"; }
notes() { cd "${dev:?}/notes/notes"; }
rr() { cd "$HOME/.config/rash"; }
tmp() { cd /tmp; }
utils() { cd "${dec:?}/utils"; }
vesmir() { cd "${der:?}/vesmir"; }
yas() { cd "${dev:?}/yasnippet"; }
# Quick jump back
cd-() { cd -; }
cdd() { cd -; }
# --- Centralized "change-to-project-directory" shortcuts ---
# -A make associative arrays
# declare -A CDMAP=(
# # variable-based dirs (fail fast if unset)
# # [latest]="$HOME/.cache/guix/checkouts/${latestRepo:?}"
# [owid]="${dec:?}/owid"
# [trackle]="${dev:?}/trackle"
# [ufo]="${dec:?}/ufo"
# [utils]="${dec:?}/utils"
# [zark]="${dec:?}/zark"
# )
cdx() {
local key=$1
if [[ -z $key ]]; then
printf 'Usage: cdx <shortcut>\nAvailable: %s\n' "${!CDMAP[@]}" | sort
return 1
fi
local target=${CDMAP[$key]}
if [[ -z $target ]]; then
printf 'cdx: unknown shortcut "%s"\n' "$key" >&2
return 1
fi
cd -- "$target" || return
}
# Usage
# $ cdx corona # goes to $dec/corona_cases
# $ cdx rr # goes to ~/.config/rash
# $ cdx latest # goes to ~/.cache/guix/checkouts/$latestRepo
# Benefits
# Single function (cdx) instead of dozens of small ones.
# Associative array keeps shortcuts centralized and easy to extend.
# Usage hint if you run cdx with no args.
# Error message if you mistype a key.
# --- Bash completion for cdx ---
_cdx_completions() {
local cur="${COMP_WORDS[COMP_CWORD]}"
COMPREPLY=( $(compgen -W "${!CDMAP[@]}" -- "$cur") )
}
complete -F _cdx_completions cdx
# Usage
# $ cdx <TAB>
# latest owid trackle ufo utils zark rr
# Create a quick test repo
create_test_repo() {
mkdir foo && cd foo || return
git init
git config user.email "${GIT_AUTHOR_EMAIL:-x@y.com}"
git config user.name "${GIT_AUTHOR_NAME:-Jim Beam}"
echo "some content" > foo.txt
git add foo.txt
git commit -m "1st commit"
"${EDITOR:-emacs -nw}" foo.txt
}
# Set up fzf key bindings and fuzzy completion
eval "$(fzf --bash)"
eval "$(zoxide init bash)"
# 🐟🐳🐠🎣🦑👽🛸🚀🧙🦊🐍💡🧠🤓👾🤖🦾🐌🐚
# Single quotes preferred: no interpolation happens here anyway, and they
# make that explicit instead of implying "$..." expansion might be wanted.
export STARSHIP_PROMPT_SYMBOL='🐚'
eval "$(starship init bash)"
#### home-bash-configuration -> .bashrc_additions: end
# Use Fish locally while keeping Bash for SSH and noninteractive commands.
# Switch only once: Fish and its children inherit this flag, so running
# `bash` from Fish opens Bash instead of replacing it with another Fish.
if [[ $- == *i* && -z ${SSH_CONNECTION-} && -z ${FISH_STARTED-} ]]; then
if command -v fish >/dev/null 2>&1; then
export FISH_STARTED=1
exec fish
fi
fi