-
Notifications
You must be signed in to change notification settings - Fork 0
/
.bash_extras
107 lines (84 loc) · 2.87 KB
/
.bash_extras
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
#!/bin/bash
RESET="\[\017\]"
NORMAL="\[\033[00m\]"
RED="\[\033[31m\]"
YELLOW="\[\033[01;33m\]"
GREEN="\[\033[32m\]"
LIGHT_GREEN="\[\033[01;32m\]"
LIGHT_BLUE="\[\033[01;34m\]"
LIGHT_PURPLE="\[\033[01;35m\]"
# Trim the directories in the prompt path to this level
PROMPT_DIRTRIM=2
# Include timestamp
TIMESTAMP=true
# Shorthand hostname
SHORT_HOSTNAME="$(hostname | sed 's|-.*||')"
# Color the dollar sign depending on exit status of last command
PROMPT_COMMAND='if [ "$?" == 0 ]; then DOLLAR_COLOR="\033[32m"; else DOLLAR_COLOR="\033[31m"; fi'
# Try to load git __git_ps1 if possible
if [ -f /usr/share/git-core/contrib/completion/git-prompt.sh ]; then
source /usr/share/git-core/contrib/completion/git-prompt.sh
fi
# Set up the prompt with GIT niceness if available
if [ "$TERM" != "dumb" ]; then
LINE_ENDING=""
if [ ! -z $PIPENV_ACTIVE ]; then
LINE_ENDING="\n"
fi
_TIMESTAMP=""
if $TIMESTAMP; then
_TIMESTAMP="${YELLOW}[\A] "
fi
# Don't print username/machine name when running as own user on own machine
_USER_HOST=""
if [ "${USER}" != "stefan" ] || [ "${SHORT_HOSTNAME}" != "stefan" ]; then
_USER_HOST="${LIGHT_GREEN}\u@${YELLOW}${SHORT_HOSTNAME}${NORMAL} "
fi
GIT_PROMPT=""
if hash __git_ps1 &> /dev/null; then
# Show the git branch if possible
GIT_PS1_SHOWDIRTYSTATE=1
GIT_PS1_SHOWCOLORHINTS=1
GIT_PS1_SHOWUPSTREAM="auto"
GIT_PROMPT=" ${LIGHT_PURPLE}\$(__git_ps1 '(%s)')${NORMAL}"
fi
# PS1="${_TIMESTAMP}${NORMAL}${LIGHT_BLUE}\w${NORMAL}${GIT_PROMPT}${LINE_ENDING}\$(echo -ne \[\${DOLLAR_COLOR}\])\$${NORMAL} "; PROMPT_DIRTRIM=${PROMPT_DIRTRIM}
PS1="${_TIMESTAMP}${_USER_HOST}${LIGHT_BLUE}\w${NORMAL}${GIT_PROMPT}${LINE_ENDING}\$(echo -ne \[\${DOLLAR_COLOR}\])\$${NORMAL} "; PROMPT_DIRTRIM=${PROMPT_DIRTRIM}
fi
cd() {
# If cd'ing to a file, cd to its directory instead
if [ $# -ne 1 ] || [ "$1" = "-" ]; then
builtin cd "$@"
return
fi
if [ -f "$1" ] && [ -d $(dirname "$1") ]; then
builtin cd $(dirname "$1")
else
builtin cd "$1"
fi
if [ -d ".venv" ] && [ -z "$VIRTUAL_ENV" ]; then
# Activate venv in directories with ".venv" folder
venv activate
elif [ -f "Pipfile" ] && [ -z "$PIPENV_ACTIVE" ]; then
# Invoke pipenv shell in directories with Pipfiles
pipenv shell
fi
}
# Convenience function to profile a python script
profile() {
local arg1=$1
python -m cProfile -o "$arg1.prof" $arg1
}
# Set breakpoint() in Python to call pudb
# export PYTHONBREAKPOINT="pudb.set_trace"
# On the datascience VM, gpg cannot use UI to ask for the password, so we need it to ask in the terminal
export GPG_TTY=$(tty)
# Create directory, then cd into it
mkcd () {
mkdir -p "$1"
cd "$1"
}
export EDITOR="$(which nano)"
battail() {
tail -f "$1" | bat --paging=never -l log "${@:2}"
}