Added r2ensource & r2dissource
This commit is contained in:
parent
0a52f2201f
commit
b10b68aa3b
@ -1,25 +0,0 @@
|
||||
#!/bin/bash
|
||||
IS_CYGWIN=false
|
||||
|
||||
case $( uname -a | awk '{ print $1 }' ) in
|
||||
Darwin) # although this is deprecated, Mac still use it
|
||||
PERM="+111"
|
||||
;;
|
||||
# Linux) ;& // Fall through does not support in OS X
|
||||
CYGWIN*)
|
||||
PERM="/111"
|
||||
IS_CYGWIN=true
|
||||
;;
|
||||
*)
|
||||
PERM="/111"
|
||||
;;
|
||||
esac
|
||||
|
||||
function __func_head() {
|
||||
echo "Usage:" ${FUNCNAME[1]} $1
|
||||
}
|
||||
|
||||
function __func_help() {
|
||||
# echo "Usage:" ${FUNCNAME[1]} $1
|
||||
echo " ${FUNCNAME[1]} $1"
|
||||
}
|
@ -78,6 +78,9 @@ if ! shopt -oq posix; then
|
||||
fi
|
||||
fi
|
||||
|
||||
function __func_head() { echo "Usage:" ${FUNCNAME[1]} $1; }
|
||||
function __func_help() { echo " ${FUNCNAME[1]} $1"; }
|
||||
|
||||
function __download {
|
||||
which curl 2>&1 > /dev/null
|
||||
if [ $? -eq 0 ]; then
|
||||
@ -109,7 +112,7 @@ function rbash_cache {
|
||||
# User specific aliases and functions
|
||||
function rbash_load {
|
||||
local f path
|
||||
echo " $1"
|
||||
echo "Load: $1"
|
||||
f=`rbash_cache "$RBASH_REMOTE/$RBASH_REPO/raw/branch/master/$RBASH_PATH/$1"`
|
||||
source "$f"
|
||||
}
|
||||
@ -169,10 +172,14 @@ function _require_jq {
|
||||
fi
|
||||
}
|
||||
|
||||
declare -A _RBASH_DICT
|
||||
function rbash-list {
|
||||
_require_jq || return 1
|
||||
echo "Available sources:"
|
||||
local _k
|
||||
for i in `__download "$RBASH_REMOTE/api/v1/repos/$RBASH_REPO/contents/$RBASH_PATH/sources/" | jq -r '.[].name'`; do
|
||||
_k=`echo -n $i | grep -o "^\d\+"`
|
||||
_RBASH_DICT["s$_k"]=$i
|
||||
grep -q -e "^rbash_load \"sources/$i\"\$" "$RBASH_CONFIG"
|
||||
if [ $? -eq 0 ]; then
|
||||
echo " * $i"
|
||||
@ -182,9 +189,63 @@ function rbash-list {
|
||||
done
|
||||
}
|
||||
|
||||
function rbash-enable {
|
||||
_require_jq || return 1
|
||||
function r2ensource {
|
||||
rbash-list
|
||||
|
||||
local _id _sel _tmp _en
|
||||
_en=()
|
||||
read -p "Enter the script id XX, delimited by space: " _ids
|
||||
for _id in $_ids; do
|
||||
_sel=${_RBASH_DICT["s$_id"]}
|
||||
if [ -z "$_sel" ]; then
|
||||
echo "No such id $_id"
|
||||
return 1
|
||||
fi
|
||||
|
||||
grep -q -e "^rbash_load \"sources/$_sel\"\$" "$RBASH_CONFIG"
|
||||
if [ $? -eq 0 ]; then
|
||||
echo "\"$_sel\" is already enabled."
|
||||
continue
|
||||
fi
|
||||
|
||||
_en+=("$_sel")
|
||||
done
|
||||
|
||||
_tmp=$( mktemp )
|
||||
cp "$RBASH_CONFIG" "$_tmp"
|
||||
for _id in "${_en[@]}"; do
|
||||
echo "rbash_load \"sources/$_id\"" >> $_tmp
|
||||
echo "Enabling $_id"
|
||||
done
|
||||
sort $_tmp > "$RBASH_CONFIG"
|
||||
rm $_tmp
|
||||
}
|
||||
|
||||
function r2dissource {
|
||||
echo "Currently enabled sources:"
|
||||
grep -e "^rbash_load \"sources/" "$RBASH_CONFIG" | cut -c 21- | tr -d '"' | sed "s/^/ $1/g"
|
||||
|
||||
local _id _dis _opts
|
||||
_dis=()
|
||||
read -p "Enter the script id XX, delimited by space: " _ids
|
||||
for _id in $_ids; do
|
||||
_dis+=("$( grep -e "^rbash_load \"sources/${_id}_" "$RBASH_CONFIG" )")
|
||||
if [ $? -ne 0 ]; then
|
||||
echo "No such id: $_id"
|
||||
return 1
|
||||
fi
|
||||
done
|
||||
|
||||
_opts=""
|
||||
for _id in "${_dis[@]}"; do
|
||||
_opts="-e \"^$( echo -n $_id | sed 's/"/\\"/g' )$\" $_opts"
|
||||
echo "Disabling "$( echo -n $_id | sed 's/rbash_load \"sources\/\([^"]\+\)"/\1/g' )
|
||||
done
|
||||
|
||||
_dis=$( mktemp )
|
||||
sh -c "grep -v $_opts \"$RBASH_CONFIG\"" > $_dis
|
||||
sort $_dis > $RBASH_CONFIG
|
||||
rm $_dis
|
||||
}
|
||||
|
||||
export PS1='This is <MACHINE_NAME>\e[1;3<COLOR_CODE>m<MACHINE_COLORED_NAME>\e[0m: \w\n\$ '
|
||||
@ -193,11 +254,8 @@ export EDITOR=vim
|
||||
# Create default source config
|
||||
if [ ! -f "$RBASH_CONFIG" ]; then
|
||||
cat <<___DEFAULT___ > "$RBASH_CONFIG"
|
||||
echo "Source:"
|
||||
rbash_load "package.sh"
|
||||
rbash_load "sources/10_aliases"
|
||||
rbash_load "sources/12_shortcuts"
|
||||
rbash_load "sources/15_gpg-agent"
|
||||
rbash_load "sources/20_fast-greps"
|
||||
rbash_load "sources/40_go-command"
|
||||
rbash_load "sources/41_pivot-command"
|
||||
|
@ -1,9 +1,5 @@
|
||||
#!/bin/bash
|
||||
|
||||
if ! $IS_CYGWIN; then
|
||||
return
|
||||
fi
|
||||
|
||||
if [ -n "$FrameworkVersion" ]; then
|
||||
alias vsshell='echo "FrameworkVersion $FrameworkVersion"'
|
||||
return
|
||||
|
Loading…
Reference in New Issue
Block a user