2020-11-03 12:07:49 -08:00
|
|
|
#!/bin/bash
|
|
|
|
# 00 will get loaded first
|
|
|
|
|
|
|
|
##-- functions which may be used by any of the alias file --#
|
|
|
|
|
2021-02-11 18:29:28 -08:00
|
|
|
group_add() {
|
|
|
|
[[ ! $(getent group $1) ]] && echo "no group $1, aborting" && return 1
|
|
|
|
echo adding group $1 to $USER
|
|
|
|
sudo usermod -a -G $1 $USER
|
|
|
|
}
|
|
|
|
|
|
|
|
user_reload() {
|
|
|
|
save=$PWD
|
|
|
|
exec su -l $USER
|
|
|
|
cd $save
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function function_list {
|
2020-11-06 14:24:10 -08:00
|
|
|
if [ $1 ]; then
|
2020-11-13 10:25:04 -08:00
|
|
|
# will list functions in passed file
|
2020-11-06 14:24:10 -08:00
|
|
|
local STR
|
|
|
|
local func
|
|
|
|
declare -a FUNCS
|
|
|
|
STR=$(grep '() {\|(){\|function' $1)
|
|
|
|
readarray -t LIST <<<"$STR"
|
|
|
|
for func in "${LIST[@]}"
|
|
|
|
do
|
|
|
|
if [[ ! $func =~ ^# ]]; then
|
2020-11-13 10:25:04 -08:00
|
|
|
func=${func#function }
|
2020-11-06 14:24:10 -08:00
|
|
|
func=${func%()?( ){}
|
|
|
|
[[ ! $func =~ ^_ ]] && FUNCS+=($func)
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
echo "${FUNCS[@]}"
|
|
|
|
else
|
2020-11-27 09:59:16 -08:00
|
|
|
# will list all sourced/declared functions available
|
2020-11-03 12:07:49 -08:00
|
|
|
echo
|
|
|
|
echo -e "\033[1;4;32m""Functions:""\033[0;34m"
|
|
|
|
declare -F | grep -v "declare -f\s_" | awk {'print $3'}
|
|
|
|
echo
|
|
|
|
echo -e "\033[0m"
|
2020-11-06 14:24:10 -08:00
|
|
|
fi
|
2020-11-03 12:07:49 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
function alias_list() {
|
|
|
|
echo
|
|
|
|
echo -e "\033[1;4;32m""Aliases:""\033[0;34m"
|
|
|
|
alias | awk {'print $2'} | awk -F= {'print $1'}
|
|
|
|
echo
|
|
|
|
echo -e "\033[0m"
|
|
|
|
}
|
|
|
|
|
|
|
|
rsynchc() { rsync --help | grep "\-$1"; }
|
|
|
|
alias rsynch="rsynchc"
|
|
|
|
|
2020-11-06 14:24:10 -08:00
|
|
|
get_shopt () {
|
|
|
|
echo $([ "$(shopt -p $1 | grep '\-s')" ] && echo on || echo off)
|
|
|
|
}
|
|
|
|
|
2020-11-03 12:07:49 -08:00
|
|
|
change-ext() {
|
2020-11-06 14:24:10 -08:00
|
|
|
local depth
|
|
|
|
local d
|
|
|
|
d=${3:-0}
|
|
|
|
let d+=1
|
|
|
|
[ $d -lt 1 ] && depth="" || depth=" -maxdepth $d "
|
|
|
|
find . $depth -name '*.'$1 -exec rename -n 's/\.'$1'/.'$2'/' \{} \;
|
|
|
|
read -p "do REALLY want to change the extensions? " -n 1 -r
|
|
|
|
echo
|
|
|
|
[[ ! $REPLY =~ ^[Yy]$ ]] && return 1
|
|
|
|
find . $depth -name '*.'$1 -exec rename 's/\.'$1'/.'$2'/' \{} \;
|
2020-11-03 12:07:49 -08:00
|
|
|
}
|
2020-11-06 14:24:10 -08:00
|
|
|
|
2020-11-03 12:07:49 -08:00
|
|
|
alias chext=change-ext
|
|
|
|
|
|
|
|
# find in any file
|
|
|
|
fif() {
|
|
|
|
grep -rnswl $1 -e $2 | more
|
|
|
|
}
|
|
|
|
|
|
|
|
# edit files
|
|
|
|
# set the system editor using EDITOR environment variable
|
|
|
|
editor() { ${EDITOR} $1; }
|