Structual bashrc

This commit is contained in:
斟酌 鵬兄 2014-08-04 17:40:25 +08:00
parent 56a34a1f12
commit 00e123d9fa
8 changed files with 180 additions and 3 deletions

23
bash/bashrc/package.sh Normal file
View File

@ -0,0 +1,23 @@
#!/bin/bash
function __func_head() {
echo "Usage:" ${FUNCNAME[1]} $1
}
function __func_help() {
# echo "Usage:" ${FUNCNAME[1]} $1
echo " ${FUNCNAME[1]} $1"
}
# Run through all sources
SDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"/sources
echo "Begin source:"
for i in $( find $SDIR -maxdepth 1 -type f -executable | sort )
do
echo " Source:" $( basename $i )
. $i
if [[ $? -ne 0 ]]; then
echo " .. failed"
fi
done

View 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
View 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"'

View 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
View 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
}

5
bash/go_command → bash/bashrc/sources/40_go-command Normal file → Executable file
View File

@ -5,9 +5,8 @@ function go() {
ARG1=$1; ARG2=$2; ARG3=$3;
if [[ -z "$ARG1" ]]; then
echo
echo "Usage: go [MODE] SITE TARGET_DIR"
echo " <up|down> [MODE] TARGET_DIR"
__func_head "[MODE] SITE TARGET_DIR"
__func_help "<up|down> [MODE] TARGET_DIR"
echo
return 1
fi

22
bash/bashrc/sources/50_blog Executable file
View 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
}

View 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
}