-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.bashrc
67 lines (60 loc) · 2.69 KB
/
.bashrc
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
#!/bin/bash
# shellcheck disable=SC1090
# If not running interactively, don't do anything
case $- in
*i*) ;;
*) return ;;
esac
# Add ~/.local/bin/ to PATH
export PATH="$HOME/.local/bin${PATH:+:${PATH}}"
# Need to be sourced before everything else so that bash-completion works as expected.
[ -f ~/.fzf.bash ] && source ~/.fzf.bash
[ -f ~/.cargo/env ] && source ~/.cargo/env
has_existing_non_scratch_tmux_session() {
if ! tmux info &>/dev/null; then
# tmux server isn't running; there's no sessions of any kind
return 1
fi
local non_scratch_sessions
non_scratch_sessions="$(tmux list-sessions -f '#{?#{==:#S,scratch},,#S}' 2>/dev/null)"
test -n "$non_scratch_sessions"
}
if [[ -z "$TMUX" ]]; then
if ! has_existing_non_scratch_tmux_session; then
# If there are no existing sessions, make a new one
tmux new-session
else
# If there _is_ an existing session, make a new one, but use the first discovered session as
# a shared session group. This is the "rogue mode" from https://github.com/zolrath/wemux
# Windows are shared (and cursors within a window). But two sessions can be in different
# windows at the same time.
#
# Note that for this to be a pleasant experience, both sessions should use the same size.
# Otherwise, when a window gets focused, it will resize both windows.
tmux new-session -t "$(tmux list-sessions -F '#S' | head -1)"
fi
fi
##################################################################################################
# Find the location of the dotfiles repository by resolving the ~/.bashrc symlink.
##################################################################################################
SOURCE="${BASH_SOURCE[0]}"
# resolve $SOURCE until the file is no longer a symlink
while [ -h "$SOURCE" ]; do
DIR="$(cd -P "$(dirname "$SOURCE")" >/dev/null 2>&1 && pwd)"
SOURCE="$(readlink "$SOURCE")"
# if $SOURCE was a relative symlink, we need to resolve it relative to the path where the symlink file was located
[[ $SOURCE != /* ]] && SOURCE="$DIR/$SOURCE"
done
DOTFILES_DIR="$(cd -P "$(dirname "$SOURCE")" >/dev/null 2>&1 && pwd)/.."
DOTFILES_DIR="$(readlink --canonicalize --no-newline "${DOTFILES_DIR}")"
export DOTFILES_DIR
unset -v DIR
unset -v SOURCE
##################################################################################################
# Source each of components in alphabetical order.
# This is where most of the customizations come from.
##################################################################################################
for rcfile in "${DOTFILES_DIR}/bashrc.d/"*.sh; do
[ -f "$rcfile" ] && source "$rcfile"
done
unset -v rcfile