-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbash_aliases
206 lines (181 loc) · 5.34 KB
/
bash_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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
# NOT ALIASES BUT HELPFUL ANYWAY
# include aliases for git
if [ -f ~/.bash_aliases_internal ]; then
. ~/.bash_aliases_internal
fi
if [ -f ~/.bash_aliases_git_internal ]; then
. ~/.bash_aliases_git_internal
fi
if [ -f ~/.bash_aliases_git ]; then
. ~/.bash_aliases_git
fi
# for ignoring certain commands to appear on history, add colon to separate commands
HISTIGNORE='git status:gis:git pull:gip:clear:exit:ls'
# enable GIT BRANCH to display on command line
get_git_branch () {
#git symbolic-ref --short HEAD;
local branchPrefix='';
local branchSufix='';
case $1 in
'type_a')
branchPrefix=' >';
branchSufix='<';
;;
'type_b')
branchPrefix=' :';
branchSufix=':';
;;
'type_c')
branchPrefix=' (';
branchSufix=')';
;;
'')
;;
esac
git branch 2> /dev/null | sed -e '/^[^*]/d' -e "s/* \(.*\)/$branchPrefix\1$branchSufix/";
}
export PS1="\[\033[01;32m\]\u \[\033[01;34m\]\w\[\033[01;33m\]\$(get_git_branch type_b)\[\033[00m\] $ "
# quick directory movement
alias ..='cd ..';
alias ...='cd ../..';
alias ....='cd ../../..';
alias .....='cd ../../../..';
alias resource='source ~/.bashrc';
alias askrm='rm -i';
# print the current time
alias now='date +%T';
# edit the selected bash config file
function editbash {
if [[ "$1" == "a" ]]; then
subl ~/.bash_aliases;
elif [[ "$1" == "h" ]]; then
subl ~/.bash_history;
elif [[ "$1" == "g" ]]; then
subl ~/.bash_aliases_git;
#elif [[ "$1" == "f" ]]; then
# subl ~/.bash_functions
else
subl ~/.bashrc;
fi
}
function dye {
local color='';
case $1 in
'black')
color='\033[0;30m';;
'red' )
color='\033[0;31m';;
'green' )
color='\033[0;32m';;
'orange' )
color='\033[0;33m';;
'blue' )
color='\033[0;34m';;
'purple' )
color='\033[0;35m';;
'cyan' )
color='\033[0;36m';;
'light_gray' )
color='\033[0;37m';;
'light_green' )
color='\033[1;32m';;
'yellow' )
color='\033[1;33m';;
'light_blue' )
color='\033[1;34m';;
'white' )
color='\033[1;37m';;
'undye')
color='\033[0m';;
*)
local usage='';
usage="$(dye black)black$(dye undye)";
usage="$usage|$(dye yellow)yellow$(dye undye)";
usage="$usage|$(dye orange)orange$(dye undye)";
usage="$usage|$(dye red)red$(dye undye)";
usage="$usage|$(dye light_green)light_green$(dye undye)";
usage="$usage|$(dye green)green$(dye undye)";
usage="$usage|$(dye cyan)cyan$(dye undye)";
usage="$usage|$(dye light_blue)light_blue$(dye undye)";
usage="$usage|$(dye blue)blue$(dye undye)";
usage="$usage|$(dye purple)purple$(dye undye)";
usage="$usage|$(dye light_gray)light_gray$(dye undye)";
usage="$usage|$(dye white)white$(dye undye)";
usage="$usage|$(dye undye)undye$(dye undye)";
echo -e "Usage: $ dye {$usage}";
return;;
esac
echo $color;
}
readonly GOTO_MAP_FILE='/home/user/.goto_map.xml';
readonly GOTO_TEST_FILE='/home/user/test.xml';
function goto () {
tags=($(grep -oP '(?<=tag>)[^<]+' ${GOTO_MAP_FILE}))
paths=($(grep -oP '(?<=path>)[^<]+' ${GOTO_MAP_FILE}))
for i in ${!tags[*]}; do
if [[ "${tags[${i}]}" == "${1}"* ]]; then
echo "cd" "${paths[${i}]}" "(${tags[${i}]})";
cd "${paths[${i}]}";
break;
fi
done
}
function mapme () {
local tagPath=$(__mapme_generate_tag_path);
local tagName=$(__mapme_generate_tag_name "${1}");
__mapme_insert 'print';
}
function _mapme_test () {
local tagName='';
if [ -n "${1}" ]; then
tagName="${1}";
else
local basePath=${PWD##*/};
tagName=${basePath,,};
fi
echo $(sed -n "\|${tagName}|=" $(__mapme_file 'test'));
#check if tag/address already exist on the file
#if so, do something
#if else; do great
}
function readConfigFileTest()
{
local continue=0;
local -a vars;
vars[0]="\[general\]";
vars[1]='\[carambola\]';
# section="$1"
# found=false
# while read line
# do
# [[ $found == false && "$line" != "[$section]" ]] && continue
# [[ $found == true && "${line:0:1}" = '[' ]] && break
# found=true
# echo "$line"
# done < /home/b4b06/test.txt
while read var value
do
local pattern="\[\w+\]";
if [[ "${var}" =~ $pattern ]]; then
if [[ "${var}" =~ ${vars[0]} || "${var}" =~ ${vars[1]} ]]; then
continue=1;
else
continue=0;
fi
fi
if [[ "${continue}" == 1 ]]; then
IFS='=' read -ra ADDR <<< "$var"
if [[ -n ${ADDR[0]} && -n ${ADDR[1]} ]]; then
local "${ADDR[0]}"="${ADDR[1]}";
echo "Variable: ${ADDR[0]} with value: ${ADDR[1]}";
fi
fi
# for i in "${ADDR[@]}"; do
# echo "$i"eita
# done
# echo "$var"
# echo "$var"="$value"
# export "$var"="$value"
done < /home/b4b06/test.txt
echo "sera que deu $eita";
}