-
Notifications
You must be signed in to change notification settings - Fork 0
/
mybash.bash
executable file
·120 lines (102 loc) · 2.65 KB
/
mybash.bash
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
#!/bin/bash
# mybash main script
# author: Helder Vasconcelos
export PS1='[\[\e[1;34m\]\u@\h\[\e[0m\]..\W] '
install_dir=$HOME/.mybash
install_log_file=$install_dir/mybash_install.log
. $install_dir/installf.bash
myloaddir() {
if [[ -d $1 ]]; then
files=`find $1 -iname "*.bash"`
for file in $files; do
. $file
done
else
echo "Error: Failed to load directory $1"
fi
}
myexpa() {
export PATH=$PATH:$*
}
myexpb(){
export PATH=$*:$PATH
}
myladd(){
echo "$1:$2" >> $HOME/.mybash/IDIR
}
mylls(){
dirs=`cat $HOME/.mybash/IDIR`
for entry in $dirs; do
name=`echo $entry | awk -F : '{print $1}'`
dir=`echo $entry | awk -F : '{print $2}'`
echo "$name $dir"
done
}
mylgo(){
if [[ $1 ]]; then
dirs=`cat $HOME/.mybash/IDIR`
for entry in $dirs; do
name=`echo $entry | awk -F : '{print $1}'`
dir=`echo $entry | awk -F : '{print $2}'`
if [[ $name == $1 ]];then
cd $dir
return
fi
done
echo "Error: Directory entry not found"
else
echo "Syntax Error: goto <dir_entry>"
fi
}
myenable_realtime_history(){
export HISTCONTROL=erasedups
# ... and don't clobber the history when closing multiple shells
shopt -s histappend
# ... and keep multi line commands together
shopt -s cmdhist
#Real-time history export amongst bash terminal windows (stackoverflow)
export HISTCONTROL=ignoredups:erasedups # no duplicate entries
export HISTSIZE=100000 # big big history
export HISTFILESIZE=100000 # big big history
shopt -s histappend # append to history, don't overwrite it
# Save and reload the history after each command finishes
export PROMPT_COMMAND="history -a; history -c; history -r; $PROMPT_COMMAND"
}
_mylgo(){
local cur
local locals=""
COMPREPLY=()
[[ -e $HOME/.mybash/IDIR ]] && locals=$(cat $HOME/.mybash/IDIR | cut -d ':' -f 1)
cur="${COMP_WORDS[COMP_CWORD]}"
COMPREPLY=($(compgen -W "${locals}" $cur))
}
complete -F _mylgo mylgo
myprofset(){
if [[ -e $HOME/.mybash/profiles/$1.bash ]]; then
echo $1 > $HOME/.mybash/PROFILE
echo "Loading Profile [ $1 ]"
. $HOME/.mybash/profiles/$1.bash
else
echo "Error: Profile $1 doesn't exist"
fi
}
myprofls(){
for profile in `ls $HOME/.bash/profiles/*.my`; do
echo $profile
done
}
mybash_version(){
echo "mybash version =$(cat $install_dir/.git/refs/heads/master)"
}
mybash_isLinux(){
[[ `uname -s` == "Linux" ]] && return 0
return 1
}
mybash_isMac(){
[[ `uname -s` == "Darwin" ]] && return 0
return 1
}
#mybash_update
> $HOME/.mybash/IDIR
myloaddir $HOME/.mybash/plugin
myloaddir $HOME/.mybash/alias