-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.bashrc
115 lines (94 loc) · 3.18 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
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
#!/bin/bash
# ~/.bashrc: executed by bash(1) for non-login shells.
# see /usr/share/doc/bash/examples/startup-files (in the package bash-doc)
# for examples
# If not running interactively, don't do anything
case $- in
*i*) ;;
*) return;;
esac
# Bash shell options
shopt -s histappend
shopt -s checkwinsize
shopt -s cmdhist
shopt -s complete_fullquote
shopt -s dotglob
# Bash variables see bash(1) for more details on configuration
HISTSIZE=20000
HISTFILESIZE=20000
HISTCONTROL=ignoreboth
TERM=tmux-256color
set_ps1 () {
local __PREVIOUS_EXIT_CODE="$?"
# Colors
local __GREEN="\\[\\033[01;32m\\]"
local __BLUE="\\[\\033[01;34m\\]"
local __RED="\\[\\033[01;31m\\]"
local __RESET="\\[\\033[0m\\]"
# Prompt Components
local __USER="$__GREEN\\u$__RESET"
local __HOST="$__GREEN\\h$__RESET"
local __WORKING_DIRECTORY="$__BLUE\\w$__RESET"
local __EXIT_CODE=""
local __GIT_BRANCH=""
local __CURRENT_BRANCH=$(__git_ps1)
local __VITRUAL_ENV_PROMPT=""
local __TIME_NOW=$__GREEN$(date +'%H:%M:%S')$__RESET
if [ ! -z $VIRTUAL_ENV_PROMPT ]; then
__VITRUAL_ENV_PROMPT="$__GREEN$VIRTUAL_ENV_PROMPT$__RESET"
fi
# Set color based on exit code status
if [ $__PREVIOUS_EXIT_CODE -eq 0 ]; then
__EXIT_CODE="$__GREEN($__PREVIOUS_EXIT_CODE)$__RESET"
else
__EXIT_CODE="$__RED($__PREVIOUS_EXIT_CODE)$__RESET"
fi
if ! command -v __git_ps1 &> /dev/null ; then
. /etc/bash_completion.d/git-prompt
fi
# Strip leading/trailing spaces
if [ ! -z $__CURRENT_BRANCH ]; then
__CURRENT_BRANCH=$(printf $__CURRENT_BRANCH)
fi
# Set color of git branch
if [[ $__CURRENT_BRANCH =~ (master|main|develop) ]]; then
__GIT_BRANCH="$__RED$__CURRENT_BRANCH$__RESET"
else
__GIT_BRANCH="$__GREEN$__CURRENT_BRANCH$__RESET"
fi
PS1="user=${__USER} host=${__HOST} time=${__TIME_NOW} rc=${__EXIT_CODE} branch=${__GIT_BRANCH:=no_git} venv=${__VITRUAL_ENV_PROMPT} pwd=${__WORKING_DIRECTORY}\n$ "
}
PROMPT_COMMAND=set_ps1
# enable color support of ls and also add handy aliases
if [ -x /usr/bin/dircolors ]; then
test -r ~/.dircolors && eval "$(dircolors -b ~/.dircolors)" || eval "$(dircolors -b)"
alias ls='ls --color=auto'
fi
# Alias definitions.
[ -f "$HOME"/.bash_aliases ] && . "$HOME"/.bash_aliases
[ -f "$HOME"/.local/bin ] && . export $PATH=$PATH:$HOME/.local/bin
# 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
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
# Set umask, {owner,group,others}
# 022 = rwx, rx, rx
umask 022
# Add custom go location to path
export PATH=~/.local/bin/go/bin:$PATH
# Start tmux if not already
if command -v tmux &> /dev/null && [ -n "$PS1" ] && [[ "$TERM" =~ tmux ]] && [ -z "$TMUX" ]; then
if ! tmux ls | grep "(attached)"; then
if ! tmux attach; then
tmux new-session -s dev -n shell -d
tmux new-window -n vim -c ${HOME}/repos
tmux attach -t dev
fi
fi
fi