Structual bashrc
This commit is contained in:
24
bash/bashrc/sources/09_ssh-agent
Executable file
24
bash/bashrc/sources/09_ssh-agent
Executable file
@@ -0,0 +1,24 @@
|
||||
#!/bin/bash
|
||||
|
||||
SSH_ENV="$HOME/.ssh/environment"
|
||||
|
||||
function start_agent {
|
||||
echo "Initialising new SSH agent..."
|
||||
/usr/bin/ssh-agent | sed 's/^echo/#echo/' > "${SSH_ENV}"
|
||||
echo succeeded
|
||||
chmod 600 "${SSH_ENV}"
|
||||
. "${SSH_ENV}" > /dev/null
|
||||
/usr/bin/ssh-add;
|
||||
}
|
||||
|
||||
# Source SSH settings, if applicable
|
||||
|
||||
if [ -f "${SSH_ENV}" ]; then
|
||||
. "${SSH_ENV}" > /dev/null
|
||||
#ps ${SSH_AGENT_PID} doesn't work under cywgin
|
||||
ps -ef | grep ${SSH_AGENT_PID} | grep ssh-agent$ > /dev/null || {
|
||||
start_agent;
|
||||
}
|
||||
else
|
||||
start_agent;
|
||||
fi
|
17
bash/bashrc/sources/10_aliases
Executable file
17
bash/bashrc/sources/10_aliases
Executable file
@@ -0,0 +1,17 @@
|
||||
#!/bin/bash
|
||||
|
||||
# directory navigations
|
||||
alias p=pushd
|
||||
alias pp='pushd +2'
|
||||
alias p3='pushd +3'
|
||||
alias p4='pushd +4'
|
||||
alias o=popd
|
||||
alias d='dirs -v'
|
||||
|
||||
# fast greps
|
||||
alias grep='grep --color=auto --exclude=\.svn'
|
||||
alias grepphp='grep -n --include=*.php'
|
||||
alias grepjs='grep -n --include=*.js'
|
||||
|
||||
# Wget prefix
|
||||
alias wget='wget --directory-prefix="$HOME/Downloads"'
|
34
bash/bashrc/sources/20_fast-greps
Executable file
34
bash/bashrc/sources/20_fast-greps
Executable file
@@ -0,0 +1,34 @@
|
||||
#!/bin/bash
|
||||
|
||||
function grepmysql () {
|
||||
if [[ -z "$1" ]]; then
|
||||
__func_head "MySQL_SERVER_NAME [WITH_OPTIONS]"
|
||||
echo
|
||||
else
|
||||
if [[ -z "$2" ]]; then
|
||||
grep -i $1 ~/.mysql_pass | awk 'BEGIN{FS=":"}{ print $2 }'
|
||||
else
|
||||
grep -i $1 ~/.mysql_pass | awk 'BEGIN{FS=":"}{ print $2" "$3 }'
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
function grepdb () {
|
||||
if [[ -z "$1" ]]; then
|
||||
__func_head "DB_NAME"
|
||||
echo
|
||||
else
|
||||
grep $1 ~/.db_pass | awk 'BEGIN{FS=":"}{ print $2 }'
|
||||
fi
|
||||
}
|
||||
|
||||
function greptype() {
|
||||
if [[ -z "$1" ]]; then
|
||||
__func_head "TYPE GREP_ARGS"
|
||||
echo
|
||||
else
|
||||
CMD="grep --color=auto -n --include=*.$1"
|
||||
shift
|
||||
$CMD $@
|
||||
fi
|
||||
}
|
45
bash/bashrc/sources/30_mysql
Executable file
45
bash/bashrc/sources/30_mysql
Executable file
@@ -0,0 +1,45 @@
|
||||
#!/bin/bash
|
||||
|
||||
function mysqlo () {
|
||||
if [[ -z "$1" ]]; then
|
||||
__func_head "SERVER_NAME"
|
||||
echo
|
||||
else
|
||||
PASS=$(grepmysql $1 true)
|
||||
if [[ -z "$PASS" ]]; then
|
||||
echo "Server not found in config: $1"
|
||||
return 1
|
||||
|
||||
fi
|
||||
|
||||
PS_SQL=$(grep -i $1 ~/.mysql_pass | awk 'BEGIN{FS=":"}{ print $4 }')
|
||||
USER=$(grep -i $1 ~/.mysql_pass | awk 'BEGIN{FS=":"}{ print $5 }')
|
||||
|
||||
export MYSQL_PS1="$PS_SQL> "
|
||||
|
||||
shift
|
||||
|
||||
echo $__mysql
|
||||
mysql -u $USER --password=$PASS $@
|
||||
unset PS_SQL
|
||||
fi
|
||||
}
|
||||
|
||||
function mysqls () {
|
||||
if [[ -z "$1" ]]; then
|
||||
__func_head "SERVER_NAME DATABASE_NAME SQL_FILE"
|
||||
echo
|
||||
else
|
||||
USER=$(grep -i $1 ~/.mysql_pass | awk 'BEGIN{FS=":"}{ print $5 }')
|
||||
PASS=$(grepmysql $1 true)
|
||||
|
||||
if [[ -z "$PASS" ]]; then
|
||||
echo "Server not found in config: $1"
|
||||
return 1
|
||||
|
||||
fi
|
||||
|
||||
mysql -u $USER --password=$PASS -D $2 < $3
|
||||
fi
|
||||
}
|
||||
|
139
bash/bashrc/sources/40_go-command
Executable file
139
bash/bashrc/sources/40_go-command
Executable file
@@ -0,0 +1,139 @@
|
||||
#!/bin/bash
|
||||
# go command
|
||||
|
||||
function go() {
|
||||
ARG1=$1; ARG2=$2; ARG3=$3;
|
||||
|
||||
if [[ -z "$ARG1" ]]; then
|
||||
__func_head "[MODE] SITE TARGET_DIR"
|
||||
__func_help "<up|down> [MODE] TARGET_DIR"
|
||||
echo
|
||||
return 1
|
||||
fi
|
||||
|
||||
NAV=false;
|
||||
case "$ARG1" in
|
||||
p)
|
||||
CC='pushd' ;;
|
||||
c)
|
||||
CC='cd' ;;
|
||||
e)
|
||||
CC='echo' ;;
|
||||
up|down)
|
||||
NAV=true ;;
|
||||
*)
|
||||
CC='cd'
|
||||
ARG3=$ARG2
|
||||
ARG2=$ARG1
|
||||
;;
|
||||
esac
|
||||
|
||||
if [ $NAV = true ]; then
|
||||
__go_nav $ARG1 $ARG2 $ARG3
|
||||
return 0;
|
||||
fi
|
||||
|
||||
if [[ -f ~/.go_conf ]]; then
|
||||
source ~/.go_conf
|
||||
else
|
||||
echo "Cannot source config file"
|
||||
return 1;
|
||||
fi
|
||||
|
||||
SITE=$(ls $UDEV|grep -m 1 $ARG2)
|
||||
if [[ -z "$SITE" ]]; then
|
||||
echo "No such site: $ARG2"
|
||||
ls $UDEV -1 | sed 's/^/ /g'
|
||||
return 1
|
||||
fi
|
||||
|
||||
if [[ -z "$ARG3" ]]; then
|
||||
$CC $UDEV/$SITE
|
||||
return 0
|
||||
fi
|
||||
|
||||
for LOC in ${LOCS[@]}
|
||||
do
|
||||
LOCATION=$(ls $UDEV/$SITE/$LOC/ 2> /dev/null | grep -m 1 $ARG3)
|
||||
if [[ -n "$LOCATION" ]]; then
|
||||
LOCATION="$LOC/$LOCATION"
|
||||
break;
|
||||
fi
|
||||
done
|
||||
|
||||
if [[ -n "$LOCATION" ]]; then
|
||||
$CC $UDEV/$SITE/$LOCATION/
|
||||
return 0
|
||||
else
|
||||
echo "Location '$ARG3' not found under: $SITE"
|
||||
return 1
|
||||
fi
|
||||
|
||||
return 1
|
||||
}
|
||||
|
||||
__go_nav() {
|
||||
ARG1=$1; ARG2=$2; ARG3=$3;
|
||||
case "$ARG2" in
|
||||
p)
|
||||
CC='pushd' ;;
|
||||
c|"")
|
||||
CC='cd' ;;
|
||||
e)
|
||||
CC='echo' ;;
|
||||
|
||||
*)
|
||||
CC='cd'
|
||||
ARG3=$ARG2
|
||||
;;
|
||||
esac
|
||||
|
||||
if [[ "$ARG1" == "up" ]]; then
|
||||
IFS="/" read -a PWDA <<< "$(pwd)"
|
||||
|
||||
MARK=0
|
||||
LISTOF=''
|
||||
for i in "${!PWDA[@]}"
|
||||
do
|
||||
if [[ "${PWDA[$i]}" =~ $ARG3 ]]; then
|
||||
MARK=$i
|
||||
fi
|
||||
|
||||
if [[ -n "${PWDA[$i]}" ]]; then
|
||||
LISTOF="$LISTOF\n ${PWDA[$i]}";
|
||||
fi
|
||||
done
|
||||
|
||||
if [ -z "$ARG3" ]; then
|
||||
MARK=$(( $MARK - 1 ))
|
||||
fi
|
||||
|
||||
if [[ $MARK -eq 0 ]]; then
|
||||
echo "No such token in up stack: $ARG3"
|
||||
echo -e $LISTOF;
|
||||
echo
|
||||
return 1
|
||||
fi
|
||||
|
||||
DIR='/'
|
||||
|
||||
for (( i=1; i<=$MARK; i++ ))
|
||||
do
|
||||
DIR="$DIR${PWDA[$i]}/"
|
||||
done
|
||||
|
||||
else
|
||||
if [ -z "$ARG3" ]; then
|
||||
DIR=$(find . -maxdepth 1 -type d | head -n 2 | tail -n 1)
|
||||
else
|
||||
DIR=$(find . -type d -name '*'$ARG3'*')
|
||||
if [[ -z $DIR ]]; then
|
||||
|
||||
echo "Directory not found: $ARG3"
|
||||
return 1
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
|
||||
$CC $DIR
|
||||
}
|
22
bash/bashrc/sources/50_blog
Executable file
22
bash/bashrc/sources/50_blog
Executable file
@@ -0,0 +1,22 @@
|
||||
#!/bin/bash
|
||||
|
||||
if [[ ! -f ~/wconvv/native/bin ]]; then
|
||||
return 1
|
||||
fi
|
||||
|
||||
export PATH=$PATH:~/wconv/native/bin/
|
||||
|
||||
function blog () {
|
||||
if [[ -z 'command -v cj' ]]; then
|
||||
echo "Cannot find cj"
|
||||
return 1
|
||||
fi
|
||||
|
||||
if [[ -z "$1" ]]; then
|
||||
__func_head "CONTENT(CJ)"
|
||||
echo
|
||||
else
|
||||
FILE=$(date +%Y%m%d)
|
||||
echo "$1 " | xargs -d' ' cj >> ~/blog/$FILE
|
||||
fi
|
||||
}
|
13
bash/bashrc/sources/60_diagnostics
Executable file
13
bash/bashrc/sources/60_diagnostics
Executable file
@@ -0,0 +1,13 @@
|
||||
#!/bin/bash
|
||||
|
||||
function catlog () {
|
||||
if [[ -z "$1" ]]; then
|
||||
__func_head "FILE"
|
||||
echo " Will exclude:"
|
||||
cat ~/.settings/checklog_exclude | awk '{ print " "$1 }'
|
||||
echo
|
||||
else
|
||||
EXCLUDE=$(awk '{ printf("(%s)|", $1) }' ~/.settings/checklog_exclude | sed 's/|$//')
|
||||
egrep -v $EXCLUDE $1
|
||||
fi
|
||||
}
|
Reference in New Issue
Block a user