-
Notifications
You must be signed in to change notification settings - Fork 0
/
.bash_aliases
158 lines (135 loc) · 4.35 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
#!/bin/bash
expand_alias()
{
local alias=$({ alias $1 || echo $1; } 2>/dev/null)
echo "${alias#*=}"
}
if which lsd &>/dev/null ; then
alias ll="lsd -halF --group-dirs=first"
alias tree="lsd -AF --group-dirs=first --tree"
else
alias ll="$(expand_alias ls) -halF --group-directories-first"
fi
alias repwd='cd "${PWD}"' # refresh pwd when it gets pulled out from unerneath you
alias check_IFS="[[ \"\${IFS}\" == $' \t\n' ]] && echo true || echo false"
alias reset_IFS="IFS=$' \t\n'"
# regurgitate the input with entries seperated by the specified character
OFS()
{
local IFS=$1 ; shift
echo "$*"
}
for_each()
{
local action="$1" ; shift
local it
eval 'until [[ $# == 0 ]] ; do
it="$1"
if [[ -p "${it}" ]] ; then
# "it" is a named pipe. Read items from it. `for_each "..." <(...`
while read it ; do
'"${action}"'
done < ${it}
else
# "it" is a literal
'"${action}"'
fi
shift
done
# No explicit arguments. Check if any are being piped to us
while read it ; do
'"${action}"'
done'
}
any()
{
local condition="$1" ; shift
for_each "${condition} && return 0" "$@"
}
all()
{
local condition="$1" ; shift
for_each "${condition} || return 1" "$@"
}
__zip_internal()
{
local truncate=$1 ; shift
local with; [[ $# == 3 ]] && { with="$1" ; shift; }
for array in array{1,2} ; do
if [[ $(declare -p $1 2>/dev/null) =~ declare\ -a ]] ; then
# arg is the name of an array
local -n ${array}=$1
elif [[ -p $1 ]] ; then
# arg is a named pipe. `zip <(...'
local ${array}
read -a ${array} < $1
elif [[ $(declare -p $1 2>/dev/null) =~ declare\ -A ]] ; then
echo "__zip_internal: associative arrays are not currently supported"; return 1
else
echo "__zip_internal: expected the name of an array or an fd, got: \`$1'" ; return 1
fi
shift
done
local indexes1=( ${!array1[@]} )
local indexes2=( ${!array2[@]} )
if ${truncate} ; then
# Figure out how long to make the output array.
# Use the shorter of the two input arrays' lengths.
local len1=${#array1[@]}
local len2=${#array2[@]}
local len=$(( len1 < len2 ? len1 : len2 ))
# Iterate over the indexes of the individual arrays.
# This lets us handle sparse input arrays nicely.
local i1 i2 out
for ((i=0; i<len; i++)) ; do
i1=${indexes1[$i]}
i2=${indexes2[$i]}
out[$i]="${array1[$i1]}${with:-}${array2[$i2]}"
done
else
# Figure out how long to make the output array.
# This time we use the last set index for the length of each array,
# and we use the larger one as our output length.
local last1=${indexes1[-1]}
local last2=${indexes2[-1]}
local len=$(( last1 > last2 ? last1+1 : last2+1 ))
local maybe_with out
for ((i=0; i<len; i++)) ; do
# If both arrays aren't set at this index, don't print anything between them.
[[ -v array1[$i] && -v array2[$i] ]] && maybe_with="${with}" || maybe_with=""
out[$i]="${array1[$i]:-}${maybe_with}${array2[$i]:-}"
done
fi
echo "${out[@]}"
}
alias zipf="__zip_internal false" # zip full
alias zips="__zip_internal true" # zip short
################################################################################
#
# solidfire-specific stuff
#
################################################################################
alias vl_update="vl_setup update && pipenv update && pip install --upgrade pylint"
alias sfssh="ssh -o StrictHostKeyChecking=no -o IdentityFile=~/.ssh/solidfire_dev_rsa"
__source_internal()
{
local shell=$1
which ${shell} || return 1
export ${shell^^}_HOME="$(dirname $(realpath $(which ${shell})))/.."
until
bash --init-file <(cat <<EOF
source ~/.bash_profile
SSH_CLIENT=''
PS1="${PS1//\\u/$shell}"
$(${shell} --source)
EOF
)
do
echo "Continue? [1,2]"
select cont in y n ; do
[[ "${cont}" == n ]] && return || break
done
done
}
alias source_bashutils="__source_internal bashutils"
alias source_ebash="__source_internal ebash"