-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreflekt
64 lines (56 loc) · 1.27 KB
/
reflekt
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
#
# bashrc/reflect
#
# "I write shell scripts to rewrite my shell scripts"
# self editing bashrc
#
# dependencies
# tryhard
# tryfind
# /bin/vim
#
######
alias sob="source $HOME/.bashrc"
BASHRC="$(dirname $(realpath ${BASH_SOURCE[0]}))"
_reflect_edit () {
local SECTION=$1
local JUMP=$2
# absolute nonsense: if searching file `functions' we want to land on the definition
# not the preceding block comment. otherwise we want to search anywhere in the line
if [[ $JUMP ]]; then
if [[ $SECTION == f* ]]; then
JUMP="+/^${JUMP}"
else JUMP="+/${JUMP}"
fi
fi
tryhard -g vim -S "$BASHRC\/.bashvimrc"\ $JUMP "$BASHRC\/$SECTION"
}
_reflect_source () {
tryhard -g source "$BASHRC\/$1"
}
# bashrc ()
#
# edit any section of bashrc and immediately apply it
# to the current shell
#
# Usage: bashrc [-s] [section]
# -s sources the file
# otherwise edits then sources
#
# 4strid (Astrid Ivy)
# 2019-02-23
bashrc () {
if [[ $1 == "-s" ]]; then
if [[ ! $2 ]]; then
_reflect_source bashrc
else
_reflect_source $2
fi
elif [[ ! $1 ]]; then
_reflect_edit bashrc && _reflect_source bashrc
elif [[ $1 == ".bashrc" ]]; then
vim $HOME/.bashrc && source $HOME/.bashrc
else
_reflect_edit $@ && _reflect_source $1
fi
}