forked from dwmkerr/dotfiles
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathshell.sh
More file actions
121 lines (104 loc) · 4.9 KB
/
shell.sh
File metadata and controls
121 lines (104 loc) · 4.9 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
# IMPORTANT:
#
# There is no shebang in this script. This will be sourced from the user's
# current shell. So we might be using bash, zsh, etc. If we use an explicit
# shebang, we can guarantee the shell which will interpret the script, but
# cannot conditionally set up the user's _current_ shell.
#
# See the section near the end where we are sourcing auto-complete settings for
# an example of why this matters. If we use a shebang in this script, we'll only
# ever source auto-completions for the shell in the shebang.
# If we are not running interactively do not continue loading this file.
case $- in
*i*) ;;
*) return;;
esac
# Set our preferred editor (both visual and line mode to be safe).
EDITOR=vi
VISUAL=vi
# Setup the path. Add sbin.
export PATH="/usr/local/sbin:$PATH"
# Import everything from the .shell.d folder.
for file in $HOME/.shell.d/*; do
[ -e "$file" ] || continue
source "$file"
done
# If we have a .private folder, source everything in it. This is useful for
# automatically loading things like project specific secrets.
if [[ -d $HOME/.shell-private.d ]]; then
for private in $HOME/.shell-private.d/*; do
[ -e "$private" ] || continue
source "$private"
done
fi
# Set a shell option but don't fail if it doesn't exist!
safe_set() { shopt -s "$1" >/dev/null 2>&1 || true; }
# Set some options to make working with folders a little easier. Note that we
# send all output to '/dev/null' as startup files should not write to the
# terminal and older shells might not have these options.
safe_set autocd # Enter a folder name to 'cd' to it.
safe_set cdspell # Fix minor spelling issues with 'cd'.
safe_set dirspell # Fix minor spelling issues for commands.
safe_set cdable_vars # Allow 'cd varname' to switch directory.
# Uncomment the below if you want to be able to 'cd' into directories that are
# not just relative to the current location. For example, if the below was
# uncommented we could 'cd my_project' from anywhere if 'my_project' is in
# the 'repos' folder.
# CDPATH="~:~/repos"
# Configure the history to make it large and support multi-line commands.
safe_set histappend # Don't overwrite the history file, append.
safe_set cmdhist # Multi-line commands are one entry only.
PROMPT_COMMAND='history -a' # Before we prompt, save the history.
HISTSIZE=10000 # A large number of commands per session.
HISTFILESIZE=100000 # A huge number of commands in the file.
# HISTCONTROL="ignorespace:ignoredup" # Ignore starting with space or duplicates?
# export HISTIGNORE="ls:history" # Any commands we want to not record?
# HISTTIMEFORMAT='%F %T ' # Do we want a timestamp for commands?
# Add support to the terminal for colours.
# See: https://github.com/nathanbuchar/atom-one-dark-terminal
export CLICOLOR=1
export LSCOLORS=ExFxBxDxCxegedabagacad
# We're an xterm 256bit colour terminal, just in case anyone asks...
export TERM="xterm-256color"
alias tmux="tmux -2"
if [[ $COLORTERM == gnome-* && $TERM == xterm ]] && infocmp gnome-256color >/dev/null 2>&1; then export TERM=gnome-256color
elif infocmp xterm-256color >/dev/null 2>&1; then export TERM=xterm-256color
fi
# Set the language. This is required for some Python tools.
# Fix 'perl: warning: Setting locale failed.'
export LC_ALL=en_US.UTF-8
export LANG=en_US.UTF-8
# Start tmux - as long as it is not already started and as long as we are not in
# a vscode terminal. By this point in the script we know we are in an
# interactive shell.
# https://askubuntu.com/questions/1021553/can-i-check-if-the-terminal-was-started-by-visual-studio-code
# Similar for Android:
# https://youtrack.jetbrains.com/articles/IDEA-A-19/Shell-Environment-Loading
IS_IN_IDE=0
if [[ "$TERM_PROGRAM" == "vscode" || -n "$INTELLIJ_ENVIRONMENT_READER" ]]; then
IS_IN_IDE=1
fi
if [ "${IS_IN_IDE}" != "1" ]; then
# We *are* interactive, and we are not in an IDE, so if we are not already
# in tmux, start it.
[ -z "$TMUX" ] && { tmux attach || exec tmux new-session && exit;}
fi
# Load auto-completions depending on our shell.
if [ -n "$BASH_VERSION" ]; then
# Source auto-completions from the Mac and Linux locations.
# Note that this is based on Bash Completion 2, which requires Bash 4 or onwards.
export BASH_COMPLETION_COMPAT_DIR="/usr/local/etc/bash_completion.d"
[[ -r "/usr/local/etc/shell.d/bash_completion.sh" ]] && . "/usr/local/etc/shell.d/bash_completion.sh"
if [ -f /etc/bash_completion ]; then . /etc/bash_completion; fi
elif [ -n "$ZSH_VERSION" ]; then
# Source zsh auto-completions.
fpath=($HOME/.zsh/completion $fpath)
autoload -Uz compinit && compinit -i
fi
# If it exists, source my work in progress 'context' project.
context_path="${HOME}/repos/github/dwmkerr/context/context.sh"
if [ -e "${context_path}" ]; then
source "${context_path}"
fi
# Set my preferred prompt.
set_ps1 "dwmkerr" || true