-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.my_aliases
160 lines (126 loc) · 4.46 KB
/
.my_aliases
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
#!/usr/local/bin/bash
alias rg="rg --pretty --glob '!tags' --max-columns 300 "
alias rgi="rg --pretty --ignore-case --glob '!tags' --max-columns 300 "
# -r recursive, -n line number -i case insensitive, -s no messages, -I ignore binary, -S follow symlinks
# -o matching only, -h no filename
alias g="egrep -rnisIS --color"
alias gc="egrep -rnsIS --color"
alias l="gls -l -h --color --group-directories-first --dereference-command-line-symlink-to-dir --dereference-command-line --dereference"
alias ls="gls -h --color --group-directories-first --dereference-command-line-symlink-to-dir --dereference-command-line --dereference"
alias tree="tree --dirsfirst -C"
export FZF_DEFAULT_COMMAND='rg --files --no-ignore --hidden --follow --glob "!{.git}" 2> /dev/null'
export FZF_CTRL_T_COMMAND="$FZF_DEFAULT_COMMAND"
export FZF_CTRL_R_OPTS="--layout=reverse"
bind -x '"\C-p": fzf_result=$(fzf); [[ ! -z $fzf_result ]] && vim $fzf_result'
# Might have to download the binary directly, since apt has a really old version.
eval "$(fzf --bash)"
parse_git_branch() {
branch=$(git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/\1/')
if [[ $branch =~ .*detached.* ]]; then
echo " ${branch}"
return
fi
commit=$(git rev-parse --short HEAD 2> /dev/null)
out="(${branch} @ ${commit})"
if [[ ${#out} == 5 ]]; then
return
fi
echo " $out"
}
auto_virtualenv() {
command=$(python3 ~/auto-virtualenv/venv_toggle_command.py --command)
eval $command
}
virtualenv_info() {
project_name=$(python3 ~/auto-virtualenv/venv_toggle_command.py --project-name)
if [[ -n $project_name ]]; then
echo "($project_name) "
fi
}
function timer_start {
timer=${timer:-$SECONDS}
}
function timer_stop {
timer_show=$(($SECONDS - $timer))
unset timer
}
trap 'timer_start' DEBUG
prompt_command() {
timer_stop
auto_virtualenv
history -a
history -n
}
export PROMPT_COMMAND=prompt_command
make_ps1() {
# 256 colour example thing="\[\033[0;38;5;TWO_FIVE_SIZEm\][test]\[\033[0m\] "
# rgb colour example thing="\[\033[0;38;2;R;G;Bm\][test]\[\033[0m\] "
newline="\n"
duration="\[\033[1;30m\]{⏱️ \${timer_show}s}\[\033[0m\] "
host="\[\033[1;30m\][\$(hostname -s)]\[\033[0m\] "
virtualenv="\[\033[1;32m\]\$(virtualenv_info)\[\033[0m\]"
working_path="\[\033[1;36m\]\w\[\033[0m\]"
git="\[\033[1;31m\]\$(parse_git_branch)\[\033[0m\]"
arrow="\[\033[0;34m\]\n~>\[\033[0m\] "
echo "${duration}${host}${virtualenv}${working_path}${git}${arrow}"
}
PROMPT_DIRTRIM=5
export VIRTUAL_ENV_DISABLE_PROMPT=1
export PS1=$(make_ps1);
NEWLINE="\n"
NO_COLOUR="\e[00m"
PRINTING_OFF="\["
PRINTING_ON="\]"
PROMPT_COLOUR="\033[1;4;30m"
PS1_PROMPT="\$"
PS2_PROMPT=">"
RESTORE_CURSOR_POSITION="\e[u"
SAVE_CURSOR_POSITION="\e[s"
SINGLE_SPACE=" "
TIMESTAMP="\A"
TIMESTAMP_PLACEHOLDER="\[\033[1;4;30m\]--:--\[\033[0m\]"
move_cursor_to_start_of_ps1() {
command_rows=$(history 1 | wc -l)
if [ "$command_rows" -gt 1 ]; then
let vertical_movement=$command_rows+1
else
command=$(history 1 | sed 's/^\s*[0-9]*\s*//')
command_length=${#command}
ps1_prompt_length=${#PS1_PROMPT}
let total_length=$command_length+$ps1_prompt_length
let lines=$total_length/${COLUMNS}+1
let vertical_movement=$lines+1
fi
tput cuu $vertical_movement
}
PS0_ELEMENTS=(
"$SAVE_CURSOR_POSITION" "\$(move_cursor_to_start_of_ps1)"
"$PROMPT_COLOUR" "$TIMESTAMP" "$NO_COLOUR" "$RESTORE_CURSOR_POSITION"
)
PS0=$(IFS=; echo "${PS0_ELEMENTS[*]}")
PS1_ELEMENTS=(
# Empty line after last command.
"$NEWLINE"
"$TIMESTAMP_PLACEHOLDER" "$SINGLE_SPACE" "$(make_ps1)"
)
PS1=$(IFS=; echo "${PS1_ELEMENTS[*]}")
PS2_ELEMENTS=(
"$PRINTING_OFF" "$PROMPT_COLOUR" "$PRINTING_ON" "$PS2_PROMPT"
"$SINGLE_SPACE" "$PRINTING_OFF" "$NO_COLOUR" "$PRINTING_ON"
)
PS2=$(IFS=; echo "${PS2_ELEMENTS[*]}")
shopt -s histverify
export EDITOR=vim
# Eternal bash history.
export HISTFILESIZE=
export HISTSIZE=
# export HISTTIMEFORMAT="[%F %T] "
# Change the file location because certain bash sessions truncate .bash_history file upon close.
# http://superuser.com/questions/575479/bash-history-truncated-to-500-lines-on-each-login
export HISTFILE=~/.bash_eternal_history
# Force prompt to write history after every command.
# http://superuser.com/questions/20900/bash-history-loss
# PROMPT_COMMAND="history -a; $PROMPT_COMMAND"
export PATH=~/.local/bin:$PATH
# For spacedentist spr
export PATH="/home/tanwang/.cargo/bin:$PATH"