Create the concept of enabled plugins
This allows users to disable a plugin without completely removing it. Instead, they simply remove the `plugins/enabled/*.bash` file for the plugin they want to disable. This continues the concept of "everything on" while providing greater flexibility to future users. It might be a good idea to allow turning these off by default in the future and allowing not only the `plugins/enabled/*.bash` files but also an array of `<plugin_name>` values that would search for `plugins/available/<plugin_name>.plugin.bash` to enable them. That method would make it easier for people custom tune their plugins from within their `.bash_profile` script.
This commit is contained in:
113
plugins/available/base.plugin.bash
Normal file
113
plugins/available/base.plugin.bash
Normal file
@@ -0,0 +1,113 @@
|
||||
#!/bin/bash
|
||||
|
||||
# For generic functions.
|
||||
|
||||
function ips {
|
||||
ifconfig | grep "inet " | awk '{ print $2 }'
|
||||
}
|
||||
|
||||
function down4me() {
|
||||
curl -s "http://www.downforeveryoneorjustme.com/$1" | sed '/just you/!d;s/<[^>]*>//g'
|
||||
}
|
||||
|
||||
function myip {
|
||||
res=$(curl -s checkip.dyndns.org | grep -Eo '[0-9\.]+')
|
||||
echo "Your public IP is: ${bold_green} $res ${normal}"
|
||||
}
|
||||
|
||||
# Make a directory and immediately 'cd' into it
|
||||
|
||||
function mkcd() {
|
||||
mkdir -p "$*"
|
||||
cd "$*"
|
||||
}
|
||||
|
||||
# Search through directory contents with grep
|
||||
|
||||
function lsgrep(){
|
||||
ls | grep "$*"
|
||||
}
|
||||
|
||||
# View man documentation in Preview
|
||||
pman () {
|
||||
man -t "${1}" | open -f -a $PREVIEW
|
||||
}
|
||||
|
||||
|
||||
pcurl() {
|
||||
curl "${1}" | open -f -a $PREVIEW
|
||||
}
|
||||
|
||||
pri() {
|
||||
ri -T "${1}" | open -f -a $PREVIEW
|
||||
}
|
||||
|
||||
quiet() {
|
||||
$* &> /dev/null &
|
||||
}
|
||||
|
||||
banish-cookies() {
|
||||
rm -r ~/.macromedia ~/.adobe
|
||||
ln -s /dev/null ~/.adobe
|
||||
ln -s /dev/null ~/.macromedia
|
||||
}
|
||||
|
||||
# disk usage per directory
|
||||
# in Mac OS X and Linux
|
||||
usage ()
|
||||
{
|
||||
if [ $(uname) = "Darwin" ]; then
|
||||
if [ -n $1 ]; then
|
||||
du -hd $1
|
||||
else
|
||||
du -hd 1
|
||||
fi
|
||||
|
||||
elif [ $(uname) = "Linux" ]; then
|
||||
if [ -n $1 ]; then
|
||||
du -h --max-depth=1 $1
|
||||
else
|
||||
du -h --max-depth=1
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
# One thing todo
|
||||
function t() {
|
||||
if [[ "$*" == "" ]] ; then
|
||||
cat ~/.t
|
||||
else
|
||||
echo "$*" > ~/.t
|
||||
fi
|
||||
}
|
||||
|
||||
# Checks for existence of a command
|
||||
command_exists () {
|
||||
type "$1" &> /dev/null ;
|
||||
}
|
||||
|
||||
# List all plugins and functions defined by bash-it
|
||||
function plugins-help() {
|
||||
|
||||
echo "bash-it Plugins Help-Message"
|
||||
echo
|
||||
|
||||
set | grep "()" \
|
||||
| sed -e "/^_/d" | grep -v "BASH_ARGC=()" \
|
||||
| sed -e "/^\s/d" | grep -v "BASH_LINENO=()" \
|
||||
| grep -v "BASH_ARGV=()" \
|
||||
| grep -v "BASH_SOURCE=()" \
|
||||
| grep -v "DIRSTACK=()" \
|
||||
| grep -v "GROUPS=()" \
|
||||
| grep -v "BASH_CMDS=()" \
|
||||
| grep -v "BASH_ALIASES=()" \
|
||||
| grep -v "COMPREPLY=()" | sed -e "s/()//"
|
||||
}
|
||||
|
||||
# back up file with timestamp
|
||||
# useful for administrators and configs
|
||||
buf () {
|
||||
filename=$1
|
||||
filetime=$(date +%Y%m%d_%H%M%S)
|
||||
cp ${filename} ${filename}_${filetime}
|
||||
}
|
||||
129
plugins/available/battery.plugin.bash
Normal file
129
plugins/available/battery.plugin.bash
Normal file
@@ -0,0 +1,129 @@
|
||||
#!/bin/bash
|
||||
|
||||
battery_percentage(){
|
||||
if command_exists acpi;
|
||||
then
|
||||
local ACPI_OUTPUT=$(acpi -b)
|
||||
case $ACPI_OUTPUT in
|
||||
*" Unknown"*)
|
||||
local PERC_OUTPUT=$(echo $ACPI_OUTPUT | head -c 22 | tail -c 2)
|
||||
case $PERC_OUTPUT in
|
||||
*%)
|
||||
echo "0${PERC_OUTPUT}" | head -c 2
|
||||
;;
|
||||
*)
|
||||
echo ${PERC_OUTPUT}
|
||||
;;
|
||||
esac
|
||||
;;
|
||||
*" Discharging"*)
|
||||
local PERC_OUTPUT=$(echo $ACPI_OUTPUT | head -c 26 | tail -c 2)
|
||||
case $PERC_OUTPUT in
|
||||
*%)
|
||||
echo "0${PERC_OUTPUT}" | head -c 2
|
||||
;;
|
||||
*)
|
||||
echo ${PERC_OUTPUT}
|
||||
;;
|
||||
esac
|
||||
;;
|
||||
*" Charging"*)
|
||||
local PERC_OUTPUT=$(echo $ACPI_OUTPUT | head -c 23 | tail -c 2)
|
||||
case $PERC_OUTPUT in
|
||||
*%)
|
||||
echo "0${PERC_OUTPUT}" | head -c 2
|
||||
;;
|
||||
*)
|
||||
echo ${PERC_OUTPUT}
|
||||
;;
|
||||
esac
|
||||
;;
|
||||
*" Full"*)
|
||||
echo '99'
|
||||
;;
|
||||
*)
|
||||
echo '-1'
|
||||
;;
|
||||
esac
|
||||
elif command_exists ioreg;
|
||||
then
|
||||
# http://hints.macworld.com/article.php?story=20100130123935998
|
||||
#local IOREG_OUTPUT_10_6=$(ioreg -l | grep -i capacity | tr '\n' ' | ' | awk '{printf("%.2f%%", $10/$5 * 100)}')
|
||||
#local IOREG_OUTPUT_10_5=$(ioreg -l | grep -i capacity | grep -v Legacy| tr '\n' ' | ' | awk '{printf("%.2f%%", $14/$7 * 100)}')
|
||||
local IOREG_OUTPUT=$(ioreg -n AppleSmartBattery -r | awk '$1~/Capacity/{c[$1]=$3} END{OFMT="%.2f%%"; max=c["\"MaxCapacity\""]; print (max>0? 100*c["\"CurrentCapacity\""]/max: "?")}')
|
||||
case $IOREG_OUTPUT in
|
||||
100*)
|
||||
echo '99'
|
||||
;;
|
||||
*)
|
||||
echo $IOREG_OUTPUT | head -c 2
|
||||
;;
|
||||
esac
|
||||
else
|
||||
echo "no"
|
||||
fi
|
||||
}
|
||||
|
||||
battery_charge(){
|
||||
# Full char
|
||||
local F_C='▸'
|
||||
# Depleted char
|
||||
local D_C='▹'
|
||||
local DEPLETED_COLOR='\[${normal}\]'
|
||||
local FULL_COLOR='\[${green}\]'
|
||||
local HALF_COLOR='\[${yellow}\]'
|
||||
local DANGER_COLOR='\[${red}\]'
|
||||
local BATTERY_OUTPUT='${DEPLETED_COLOR}${D_C}${D_C}${D_C}${D_C}${D_C}'
|
||||
local BATTERY_PERC=$(battery_percentage)
|
||||
|
||||
case $BATTERY_PERC in
|
||||
no)
|
||||
echo ""
|
||||
;;
|
||||
9*)
|
||||
echo "${FULL_COLOR}${F_C}${F_C}${F_C}${F_C}${F_C}${normal}"
|
||||
;;
|
||||
8*)
|
||||
echo "${FULL_COLOR}${F_C}${F_C}${F_C}${F_C}${HALF_COLOR}${F_C}${normal}"
|
||||
;;
|
||||
7*)
|
||||
echo "${FULL_COLOR}${F_C}${F_C}${F_C}${F_C}${DEPLETED_COLOR}${D_C}${normal}"
|
||||
;;
|
||||
6*)
|
||||
echo "${FULL_COLOR}${F_C}${F_C}${F_C}${HALF_COLOR}${F_C}${DEPLETED_COLOR}${D_C}${normal}"
|
||||
;;
|
||||
5*)
|
||||
echo "${FULL_COLOR}${F_C}${F_C}${F_C}${DEPLETED_COLOR}${D_C}${D_C}${normal}"
|
||||
;;
|
||||
4*)
|
||||
echo "${FULL_COLOR}${F_C}${F_C}${HALF_COLOR}${F_C}${DEPLETED_COLOR}${D_C}${D_C}${normal}"
|
||||
;;
|
||||
3*)
|
||||
echo "${FULL_COLOR}${F_C}${F_C}${DEPLETED_COLOR}${D_C}${D_C}${D_C}${normal}"
|
||||
;;
|
||||
2*)
|
||||
echo "${FULL_COLOR}${F_C}${HALF_COLOR}${F_C}${DEPLETED_COLOR}${D_C}${D_C}${D_C}${normal}"
|
||||
;;
|
||||
1*)
|
||||
echo "${FULL_COLOR}${F_C}${DEPLETED_COLOR}${D_C}${D_C}${D_C}${D_C}${normal}"
|
||||
;;
|
||||
05)
|
||||
echo "${DANGER_COLOR}${F_C}${DEPLETED_COLOR}${D_C}${D_C}${D_C}${D_C}${normal}"
|
||||
;;
|
||||
04)
|
||||
echo "${DANGER_COLOR}${F_C}${DEPLETED_COLOR}${D_C}${D_C}${D_C}${D_C}${normal}"
|
||||
;;
|
||||
03)
|
||||
echo "${DANGER_COLOR}${F_C}${DEPLETED_COLOR}${D_C}${D_C}${D_C}${D_C}${normal}"
|
||||
;;
|
||||
02)
|
||||
echo "${DANGER_COLOR}${F_C}${DEPLETED_COLOR}${D_C}${D_C}${D_C}${D_C}${normal}"
|
||||
;;
|
||||
0*)
|
||||
echo "${HALF_COLOR}${F_C}${DEPLETED_COLOR}${D_C}${D_C}${D_C}${D_C}${normal}"
|
||||
;;
|
||||
*)
|
||||
echo "${DANGER_COLOR}UNPLG\[${normal}\]"
|
||||
;;
|
||||
esac
|
||||
}
|
||||
97
plugins/available/browser.plugin.bash
Normal file
97
plugins/available/browser.plugin.bash
Normal file
@@ -0,0 +1,97 @@
|
||||
# based on https://gist.github.com/318247
|
||||
|
||||
# Usage: browser
|
||||
# pipe html to a browser
|
||||
# e.g.
|
||||
# $ echo "<h1>hi mom!</h1>" | browser
|
||||
# $ ron -5 man/rip.5.ron | browser
|
||||
|
||||
function browser() {
|
||||
if [ -t 0 ]; then
|
||||
if [ -n "$1" ]; then
|
||||
open $1
|
||||
else
|
||||
cat <<usage
|
||||
Usage: browser
|
||||
pipe html to a browser
|
||||
|
||||
$ echo '<h1>hi mom!</h1>' | browser
|
||||
$ ron -5 man/rip.5.ron | browser
|
||||
usage
|
||||
|
||||
fi
|
||||
|
||||
else
|
||||
f="/tmp/browser.$RANDOM.html"
|
||||
cat /dev/stdin > $f
|
||||
open $f
|
||||
fi
|
||||
}
|
||||
|
||||
|
||||
# pipe hot spicy interwebs into textmate and cleanup!
|
||||
#
|
||||
# Usage: wmate
|
||||
# wget into a pipe into TextMate and force Tidy (you can undo in textmate)
|
||||
# e.g.
|
||||
# $ wmate google.com
|
||||
|
||||
function wmate() {
|
||||
if [ -t 0 ]; then
|
||||
if [ -n "$1" ]; then
|
||||
wget -qO- $1 | /usr/bin/mate
|
||||
|
||||
TIDY=`/usr/bin/osascript << EOT
|
||||
tell application "TextMate"
|
||||
activate
|
||||
end tell
|
||||
|
||||
tell application "System Events"
|
||||
tell process "TextMate"
|
||||
tell menu bar 1
|
||||
tell menu bar item "Bundles"
|
||||
tell menu "Bundles"
|
||||
tell menu item "HTML"
|
||||
tell menu "HTML"
|
||||
click menu item "Tidy"
|
||||
end tell
|
||||
end tell
|
||||
end tell
|
||||
end tell
|
||||
end tell
|
||||
end tell
|
||||
end tell
|
||||
EOT`
|
||||
|
||||
else
|
||||
cat <<usage
|
||||
Usage: wmate google.com
|
||||
wget into a pipe into TextMate and force Tidy (you can undo in textmate)
|
||||
|
||||
$ wmate google.com
|
||||
usage
|
||||
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
#
|
||||
# Usage: raw google.com
|
||||
# wget into a temp file and pump it into your browser
|
||||
#
|
||||
# e.g.
|
||||
# $ raw google.com
|
||||
function raw() {
|
||||
if [ -t 0 ]; then
|
||||
if [ -n "$1" ]; then
|
||||
wget -qO- $1 | browser
|
||||
else
|
||||
cat <<usage
|
||||
Usage: raw google.com
|
||||
wget into a temp file and pump it into your browser
|
||||
|
||||
$ raw google.com
|
||||
usage
|
||||
fi
|
||||
fi
|
||||
}
|
||||
52
plugins/available/dirs.plugins.bash
Normal file
52
plugins/available/dirs.plugins.bash
Normal file
@@ -0,0 +1,52 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Directory stack navigation:
|
||||
#
|
||||
# Add to stack with: pu /path/to/directory
|
||||
# Delete current dir from stack with: po
|
||||
# Show stack with: d
|
||||
# Jump to location by number.
|
||||
|
||||
# Show directory stack
|
||||
alias d="dirs -v -l"
|
||||
|
||||
# Change to location in stack bu number
|
||||
alias 1="pushd"
|
||||
alias 2="pushd +2"
|
||||
alias 3="pushd +3"
|
||||
alias 4="pushd +4"
|
||||
alias 5="pushd +5"
|
||||
alias 6="pushd +6"
|
||||
alias 7="pushd +7"
|
||||
alias 8="pushd +8"
|
||||
alias 9="pushd +9"
|
||||
|
||||
# Clone this location
|
||||
alias pc="pushd \`pwd\`"
|
||||
|
||||
# Push new location
|
||||
alias pu="pushd"
|
||||
|
||||
# Pop current location
|
||||
alias po="popd"
|
||||
|
||||
function dirs-help() {
|
||||
echo "Directory Navigation Alias Usage"
|
||||
echo
|
||||
echo "Use the power of directory stacking to move"
|
||||
echo "between several locations with ease."
|
||||
echo
|
||||
echo "d : Show directory stack."
|
||||
echo "po : Remove current location from stack."
|
||||
echo "pc : Adds current location to stack."
|
||||
echo "pu <dir>: Adds given location to stack."
|
||||
echo "1 : Chance to stack location 1."
|
||||
echo "2 : Chance to stack location 2."
|
||||
echo "3 : Chance to stack location 3."
|
||||
echo "4 : Chance to stack location 4."
|
||||
echo "5 : Chance to stack location 5."
|
||||
echo "6 : Chance to stack location 6."
|
||||
echo "7 : Chance to stack location 7."
|
||||
echo "8 : Chance to stack location 8."
|
||||
echo "9 : Chance to stack location 9."
|
||||
}
|
||||
95
plugins/available/git.plugins.bash
Normal file
95
plugins/available/git.plugins.bash
Normal file
@@ -0,0 +1,95 @@
|
||||
#!/bin/bash
|
||||
|
||||
function git_remote {
|
||||
echo "Running: git remote add origin ${GIT_HOSTING}:$1.git"
|
||||
git remote add origin $GIT_HOSTING:$1.git
|
||||
}
|
||||
|
||||
function git_first_push {
|
||||
echo "Running: git push origin master:refs/heads/master"
|
||||
git push origin master:refs/heads/master
|
||||
}
|
||||
|
||||
function git_remove_missing_files() {
|
||||
git ls-files -d -z | xargs -0 git update-index --remove
|
||||
}
|
||||
|
||||
# Adds files to git's exclude file (same as .gitignore)
|
||||
function local-ignore() {
|
||||
echo "$1" >> .git/info/exclude
|
||||
}
|
||||
|
||||
# get a quick overview for your git repo
|
||||
function git_info() {
|
||||
if [ -n "$(git symbolic-ref HEAD 2> /dev/null)" ]; then
|
||||
# print informations
|
||||
echo "git repo overview"
|
||||
echo "-----------------"
|
||||
echo
|
||||
|
||||
# print all remotes and thier details
|
||||
for remote in $(git remote show); do
|
||||
echo $remote:
|
||||
git remote show $remote
|
||||
echo
|
||||
done
|
||||
|
||||
# print status of working repo
|
||||
echo "status:"
|
||||
if [ -n "$(git status -s 2> /dev/null)" ]; then
|
||||
git status -s
|
||||
else
|
||||
echo "working directory is clean"
|
||||
fi
|
||||
|
||||
# print at least 5 last log entries
|
||||
echo
|
||||
echo "log:"
|
||||
git log -5 --oneline
|
||||
echo
|
||||
|
||||
else
|
||||
echo "you're currently not in a git repository"
|
||||
|
||||
fi
|
||||
}
|
||||
|
||||
function git_stats {
|
||||
# awesome work from https://github.com/esc/git-stats
|
||||
# including some modifications
|
||||
|
||||
if [ -n "$(git symbolic-ref HEAD 2> /dev/null)" ]; then
|
||||
echo "Number of commits per author:"
|
||||
git --no-pager shortlog -sn --all
|
||||
AUTHORS=$( git shortlog -sn --all | cut -f2 | cut -f1 -d' ')
|
||||
LOGOPTS=""
|
||||
if [ "$1" == '-w' ]; then
|
||||
LOGOPTS="$LOGOPTS -w"
|
||||
shift
|
||||
fi
|
||||
if [ "$1" == '-M' ]; then
|
||||
LOGOPTS="$LOGOPTS -M"
|
||||
shift
|
||||
fi
|
||||
if [ "$1" == '-C' ]; then
|
||||
LOGOPTS="$LOGOPTS -C --find-copies-harder"
|
||||
shift
|
||||
fi
|
||||
for a in $AUTHORS
|
||||
do
|
||||
echo '-------------------'
|
||||
echo "Statistics for: $a"
|
||||
echo -n "Number of files changed: "
|
||||
git log $LOGOPTS --all --numstat --format="%n" --author=$a | cut -f3 | sort -iu | wc -l
|
||||
echo -n "Number of lines added: "
|
||||
git log $LOGOPTS --all --numstat --format="%n" --author=$a | cut -f1 | awk '{s+=$1} END {print s}'
|
||||
echo -n "Number of lines deleted: "
|
||||
git log $LOGOPTS --all --numstat --format="%n" --author=$a | cut -f2 | awk '{s+=$1} END {print s}'
|
||||
echo -n "Number of merges: "
|
||||
git log $LOGOPTS --all --merges --author=$a | grep -c '^commit'
|
||||
done
|
||||
else
|
||||
echo "you're currently not in a git repository"
|
||||
fi
|
||||
}
|
||||
|
||||
14
plugins/available/hg.plugins.bash
Normal file
14
plugins/available/hg.plugins.bash
Normal file
@@ -0,0 +1,14 @@
|
||||
#!/bin/bash
|
||||
hg_dirty() {
|
||||
hg status --no-color 2> /dev/null \
|
||||
| awk '$1 == "?" { print "?" } $1 != "?" { print "!" }' \
|
||||
| sort | uniq | head -c1
|
||||
}
|
||||
|
||||
hg_in_repo() {
|
||||
[[ `hg branch 2> /dev/null` ]] && echo 'on '
|
||||
}
|
||||
|
||||
hg_branch() {
|
||||
hg branch 2> /dev/null
|
||||
}
|
||||
17
plugins/available/javascript.plugins.bash
Normal file
17
plugins/available/javascript.plugins.bash
Normal file
@@ -0,0 +1,17 @@
|
||||
#!/bin/bash
|
||||
#
|
||||
# The install directory is hard-coded. TOOD: allow the directory to be specified on the command line.
|
||||
#
|
||||
|
||||
|
||||
function rails_jquery {
|
||||
curl -o public/javascripts/rails.js http://github.com/rails/jquery-ujs/raw/master/src/rails.js
|
||||
}
|
||||
|
||||
function jquery_install {
|
||||
curl -o public/javascripts/jquery.js http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js
|
||||
}
|
||||
|
||||
function jquery_ui_install {
|
||||
curl -o public/javascripts/jquery_ui.js http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.5/jquery-ui.min.js
|
||||
}
|
||||
208
plugins/available/jekyll.plugins.bash
Normal file
208
plugins/available/jekyll.plugins.bash
Normal file
@@ -0,0 +1,208 @@
|
||||
#!/bin/bash
|
||||
|
||||
editpost() {
|
||||
builtin cd "$JEKYLL_LOCAL_ROOT/_posts"
|
||||
|
||||
COUNTER=1
|
||||
NUMBER="$RANDOM"
|
||||
TMPFILE="/tmp/editpost-$NUMBER"
|
||||
|
||||
for POST in *
|
||||
do
|
||||
DATE=`echo $POST | grep -oE "[0-9]{4}-[0-9]{1,2}-[0-9]{1,2}"`
|
||||
TITLE=`cat $POST | grep -oE "title: (.+)"`
|
||||
TITLE=`echo $TITLE | sed 's/title: //'`
|
||||
echo "$COUNTER) $DATE $TITLE" >> "$TMPFILE"
|
||||
POSTS[$COUNTER]=$POST
|
||||
COUNTER=`expr $COUNTER + 1`
|
||||
done
|
||||
less $TMPFILE
|
||||
read -p "Number of post to edit: " POST_TO_EDIT
|
||||
if [ -z "$EDITOR" ]
|
||||
then
|
||||
nano "${POSTS[$POST_TO_EDIT]}"
|
||||
else
|
||||
"$EDITOR" "${POSTS[$POST_TO_EDIT]}"
|
||||
fi
|
||||
}
|
||||
|
||||
newpost() {
|
||||
|
||||
# 'builtin cd' into the local jekyll root
|
||||
|
||||
builtin cd "$JEKYLL_LOCAL_ROOT/_posts"
|
||||
|
||||
# Get the date for the new post's filename
|
||||
|
||||
FNAME_DATE=$(date "+%Y-%m-%d")
|
||||
|
||||
# If the user is using markdown formatting, let them choose what type of post they want. Sort of like Tumblr.
|
||||
|
||||
OPTIONS="Text Quote Image Audio Video Link"
|
||||
|
||||
if [ $JEKYLL_FORMATTING = "markdown" -o $JEKYLL_FORMATTING = "textile" ]
|
||||
then
|
||||
select OPTION in $OPTIONS
|
||||
do
|
||||
if [[ $OPTION = "Text" ]]
|
||||
then
|
||||
POST_TYPE="Text"
|
||||
break
|
||||
fi
|
||||
|
||||
if [[ $OPTION = "Quote" ]]
|
||||
then
|
||||
POST_TYPE="Quote"
|
||||
break
|
||||
fi
|
||||
|
||||
if [[ $OPTION = "Image" ]]
|
||||
then
|
||||
POST_TYPE="Image"
|
||||
break
|
||||
fi
|
||||
|
||||
if [[ $OPTION = "Audio" ]]
|
||||
then
|
||||
POST_TYPE="Audio"
|
||||
break
|
||||
fi
|
||||
|
||||
if [[ $OPTION = "Video" ]]
|
||||
then
|
||||
POST_TYPE="Video"
|
||||
break
|
||||
fi
|
||||
|
||||
if [[ $OPTION = "Link" ]]
|
||||
then
|
||||
POST_TYPE="Link"
|
||||
break
|
||||
fi
|
||||
done
|
||||
fi
|
||||
|
||||
# Get the title for the new post
|
||||
|
||||
read -p "Enter title of the new post: " POST_TITLE
|
||||
|
||||
# Convert the spaces in the title to hyphens for use in the filename
|
||||
|
||||
FNAME_POST_TITLE=`echo $POST_TITLE | tr ' ' "-"`
|
||||
|
||||
# Now, put it all together for the full filename
|
||||
|
||||
FNAME="$FNAME_DATE-$FNAME_POST_TITLE.$JEKYLL_FORMATTING"
|
||||
|
||||
# And, finally, create the actual post file. But we're not done yet...
|
||||
|
||||
touch "$FNAME"
|
||||
|
||||
# Write a little stuff to the file for the YAML Front Matter
|
||||
|
||||
echo "---" >> $FNAME
|
||||
|
||||
# Now we have to get the date, again. But this time for in the header (YAML Front Matter) of
|
||||
# the file
|
||||
|
||||
YAML_DATE=$(date "+%B %d %Y %X")
|
||||
|
||||
# Echo the YAML Formatted date to the post file
|
||||
|
||||
echo "date: $YAML_DATE" >> $FNAME
|
||||
|
||||
# Echo the original post title to the YAML Front Matter header
|
||||
|
||||
echo "title: $POST_TITLE" >> $FNAME
|
||||
|
||||
# And, now, echo the "post" layout to the YAML Front Matter header
|
||||
|
||||
echo "layout: post" >> $FNAME
|
||||
|
||||
# Close the YAML Front Matter Header
|
||||
|
||||
echo "---" >> $FNAME
|
||||
echo >> $FNAME
|
||||
|
||||
# Generate template text based on the post type
|
||||
|
||||
if [[ $JEKYLL_FORMATTING = "markdown" ]]
|
||||
then
|
||||
if [[ $POST_TYPE = "Text" ]]
|
||||
then
|
||||
true
|
||||
fi
|
||||
|
||||
if [[ $POST_TYPE = "Quote" ]]
|
||||
then
|
||||
echo "> Quote" >> $FNAME
|
||||
echo >> $FNAME
|
||||
echo "— Author" >> $FNAME
|
||||
fi
|
||||
|
||||
if [[ $POST_TYPE = "Image" ]]
|
||||
then
|
||||
echo "" >> $FNAME
|
||||
fi
|
||||
|
||||
if [[ $POST_TYPE = "Audio" ]]
|
||||
then
|
||||
echo "<html><audio src=\"/path/to/audio/file\" controls=\"controls\"></audio></html>" >> $FNAME
|
||||
fi
|
||||
|
||||
if [[ $POST_TYPE = "Video" ]]
|
||||
then
|
||||
echo "<html><video src=\"/path/to/video\" controls=\"controls\"></video></html>" >> $FNAME
|
||||
fi
|
||||
|
||||
if [[ $POST_TYPE = "Link" ]]
|
||||
then
|
||||
echo "[link][1]" >> $FNAME
|
||||
echo >> $FNAME
|
||||
echo "> Quote" >> $FNAME
|
||||
echo >> $FNAME
|
||||
echo "[1]: url" >> $FNAME
|
||||
fi
|
||||
fi
|
||||
|
||||
if [[ $JEKYLL_FORMATTING = "textile" ]]
|
||||
then
|
||||
if [[ $POST_TYPE = "Text" ]]
|
||||
then
|
||||
true
|
||||
fi
|
||||
|
||||
if [[ $POST_TYPE = "Quote" ]]
|
||||
then
|
||||
echo "bq. Quote" >> $FNAME
|
||||
echo >> $FNAME
|
||||
echo "— Author" >> $FNAME
|
||||
fi
|
||||
|
||||
if [[ $POST_TYPE = "Image" ]]
|
||||
then
|
||||
echo "!url(alt text)" >> $FNAME
|
||||
fi
|
||||
|
||||
if [[ $POST_TYPE = "Audio" ]]
|
||||
then
|
||||
echo "<html><audio src=\"/path/to/audio/file\" controls=\"controls\"></audio></html>" >> $FNAME
|
||||
fi
|
||||
|
||||
if [[ $POST_TYPE = "Video" ]]
|
||||
then
|
||||
echo "<html><video src=\"/path/to/video\" controls=\"controls\"></video></html>" >> $FNAME
|
||||
fi
|
||||
|
||||
if [[ $POST_TYPE = "Link" ]]
|
||||
then
|
||||
echo "\"Site\":url" >> $FNAME
|
||||
echo >> $FNAME
|
||||
echo "bq. Quote" >> $FNAME
|
||||
fi
|
||||
fi
|
||||
|
||||
# Open the file in your favorite editor
|
||||
|
||||
"$EDITOR" $FNAME
|
||||
}
|
||||
8
plugins/available/latex.plugin.bash
Normal file
8
plugins/available/latex.plugin.bash
Normal file
@@ -0,0 +1,8 @@
|
||||
#!/bin/bash
|
||||
|
||||
# add mactex to the path if its present
|
||||
MACTEX_PATH=/usr/local/texlive/2009/bin/universal-darwin
|
||||
if [[ -d $MACTEX_PATH ]]; then
|
||||
export PATH=$PATH:$MACTEX_PATH
|
||||
fi
|
||||
unset MACTEX_PATH
|
||||
50
plugins/available/nginx.plugins.bash
Normal file
50
plugins/available/nginx.plugins.bash
Normal file
@@ -0,0 +1,50 @@
|
||||
#!/bin/bash
|
||||
|
||||
function nginx_reload() {
|
||||
FILE="${NGINX_PATH}/logs/nginx.pid"
|
||||
if [ -e $FILE ]; then
|
||||
echo "Reloading NGINX..."
|
||||
PID=`cat $NGINX_PATH/logs/nginx.pid`
|
||||
sudo kill -HUP $PID
|
||||
else
|
||||
echo "Nginx pid file not found"
|
||||
return 0
|
||||
fi
|
||||
}
|
||||
|
||||
function nginx_stop() {
|
||||
FILE="${NGINX_PATH}/logs/nginx.pid"
|
||||
if [ -e $FILE ]; then
|
||||
echo "Stopping NGINX..."
|
||||
PID=`cat $NGINX_PATH/logs/nginx.pid`
|
||||
sudo kill -INT $PID
|
||||
else
|
||||
echo "Nginx pid file not found"
|
||||
return 0
|
||||
fi
|
||||
}
|
||||
|
||||
function nginx_start() {
|
||||
FILE="${NGINX_PATH}/sbin/nginx"
|
||||
if [ -e $FILE ]; then
|
||||
echo "Starting NGINX..."
|
||||
sudo $NGINX_PATH/sbin/nginx
|
||||
else
|
||||
echo "Couldn't start nginx"
|
||||
fi
|
||||
}
|
||||
|
||||
function nginx_restart() {
|
||||
FILE="${NGINX_PATH}/logs/nginx.pid"
|
||||
if [ -e $FILE ]; then
|
||||
echo "Stopping NGINX..."
|
||||
PID=`cat $NGINX_PATH/logs/nginx.pid`
|
||||
sudo kill -INT $PID
|
||||
sleep 1
|
||||
echo "Starting NGINX..."
|
||||
sudo $NGINX_PATH/sbin/nginx
|
||||
else
|
||||
echo "Nginx pid file not found"
|
||||
return 0
|
||||
fi
|
||||
}
|
||||
37
plugins/available/osx.plugin.bash
Normal file
37
plugins/available/osx.plugin.bash
Normal file
@@ -0,0 +1,37 @@
|
||||
#!/bin/bash
|
||||
|
||||
function tab() {
|
||||
osascript 2>/dev/null <<EOF
|
||||
tell application "System Events"
|
||||
tell process "Terminal" to keystroke "t" using command down
|
||||
end
|
||||
tell application "Terminal"
|
||||
activate
|
||||
do script with command "cd \"$PWD\"; $*" in window 1
|
||||
end tell
|
||||
EOF
|
||||
}
|
||||
|
||||
# this one switches your os x dock between 2d and 3d
|
||||
# thanks to savier.zwetschge.org
|
||||
function dock-switch() {
|
||||
|
||||
if [ $(uname) = "Darwin" ]; then
|
||||
|
||||
if [ $1 = 3d ] ; then
|
||||
defaults write com.apple.dock no-glass -boolean NO
|
||||
killall Dock
|
||||
|
||||
elif [ $1 = 2d ] ; then
|
||||
defaults write com.apple.dock no-glass -boolean YES
|
||||
killall Dock
|
||||
|
||||
else
|
||||
echo "usage:"
|
||||
echo "dock-switch 2d"
|
||||
echo "dock-switch 3d."
|
||||
fi
|
||||
else
|
||||
echo "sorry. you're currently not using os x"
|
||||
fi
|
||||
}
|
||||
9
plugins/available/python.plugin.bash
Normal file
9
plugins/available/python.plugin.bash
Normal file
@@ -0,0 +1,9 @@
|
||||
#!/bin/bash
|
||||
|
||||
if [ $(uname) = "Linux" ]
|
||||
then
|
||||
alias http='python2 -m SimpleHTTPServer'
|
||||
else
|
||||
alias http='python -m SimpleHTTPServer'
|
||||
fi
|
||||
|
||||
4
plugins/available/ruby.plugin.bash
Normal file
4
plugins/available/ruby.plugin.bash
Normal file
@@ -0,0 +1,4 @@
|
||||
#!/bin/bash
|
||||
function remove_gem {
|
||||
gem list | grep $1 | awk '{ print $1; }' | xargs sudo gem uninstall
|
||||
}
|
||||
16
plugins/available/rvm.plugin.bash
Normal file
16
plugins/available/rvm.plugin.bash
Normal file
@@ -0,0 +1,16 @@
|
||||
#!/bin/bash
|
||||
switch () {
|
||||
rvm $1
|
||||
local v=$(rvm_version)
|
||||
rvm wrapper $1 textmate
|
||||
echo "Switch to Ruby version: "$v
|
||||
}
|
||||
|
||||
rvm_default () {
|
||||
rvm --default $1
|
||||
rvm wrapper $1 textmate
|
||||
}
|
||||
|
||||
function rvm_version () {
|
||||
ruby --version
|
||||
}
|
||||
9
plugins/available/ssh.plugins.bash
Normal file
9
plugins/available/ssh.plugins.bash
Normal file
@@ -0,0 +1,9 @@
|
||||
#!/bin/bash
|
||||
|
||||
function add_ssh() {
|
||||
echo -en "\n\nHost $1\n HostName $2\n User $3\n ServerAliveInterval 30\n ServerAliveCountMax 120" >> ~/.ssh/config
|
||||
}
|
||||
|
||||
function sshlist() {
|
||||
awk '$1 ~ /Host$/ { print $2 }' ~/.ssh/config
|
||||
}
|
||||
8
plugins/available/subversion.plugin.bash
Normal file
8
plugins/available/subversion.plugin.bash
Normal file
@@ -0,0 +1,8 @@
|
||||
#!/bin/bash
|
||||
rm_svn(){
|
||||
find $1 -name .svn -print0 | xargs -0 rm -rf
|
||||
}
|
||||
|
||||
svn_add(){
|
||||
svn status | grep '^\?' | sed -e 's/? *//' | sed -e 's/ /\ /g' | xargs svn add
|
||||
}
|
||||
2
plugins/available/tmux.plugin.bash
Normal file
2
plugins/available/tmux.plugin.bash
Normal file
@@ -0,0 +1,2 @@
|
||||
# make sure that tmux is launched in 256 color mode
|
||||
alias tmux="TERM=xterm-256color tmux"
|
||||
50
plugins/available/vagrant.plugins.bash
Normal file
50
plugins/available/vagrant.plugins.bash
Normal file
@@ -0,0 +1,50 @@
|
||||
#!/bin/bash
|
||||
_vagrant()
|
||||
{
|
||||
cur="${COMP_WORDS[COMP_CWORD]}"
|
||||
prev="${COMP_WORDS[COMP_CWORD-1]}"
|
||||
commands="box destroy halt help init package provision reload resume ssh ssh_config status suspend up version"
|
||||
|
||||
if [ $COMP_CWORD == 1 ]
|
||||
then
|
||||
COMPREPLY=($(compgen -W "${commands}" -- ${cur}))
|
||||
return 0
|
||||
fi
|
||||
|
||||
if [ $COMP_CWORD == 2 ]
|
||||
then
|
||||
case "$prev" in
|
||||
"box")
|
||||
box_commands="add help list remove repackage"
|
||||
COMPREPLY=($(compgen -W "${box_commands}" -- ${cur}))
|
||||
return 0
|
||||
;;
|
||||
"help")
|
||||
COMPREPLY=($(compgen -W "${commands}" -- ${cur}))
|
||||
return 0
|
||||
;;
|
||||
*)
|
||||
;;
|
||||
esac
|
||||
fi
|
||||
|
||||
if [ $COMP_CWORD == 3 ]
|
||||
then
|
||||
action="${COMP_WORDS[COMP_CWORD-2]}"
|
||||
if [ $action == 'box' ]
|
||||
then
|
||||
case "$prev" in
|
||||
"remove"|"repackage")
|
||||
local box_list=$(find $HOME/.vagrant/boxes/* -maxdepth 0 -type d -printf '%f ')
|
||||
COMPREPLY=($(compgen -W "${box_list}" -- ${cur}))
|
||||
return 0
|
||||
;;
|
||||
*)
|
||||
;;
|
||||
esac
|
||||
fi
|
||||
fi
|
||||
|
||||
}
|
||||
complete -F _vagrant vagrant
|
||||
|
||||
5
plugins/available/virtualenv.plugin.bash
Normal file
5
plugins/available/virtualenv.plugin.bash
Normal file
@@ -0,0 +1,5 @@
|
||||
#!/bin/bash
|
||||
|
||||
# make sure virtualenvwrapper is enabled if availalbe
|
||||
[[ `which virtualenvwrapper.sh` ]] && . virtualenvwrapper.sh
|
||||
|
||||
148
plugins/available/z.bash
Normal file
148
plugins/available/z.bash
Normal file
@@ -0,0 +1,148 @@
|
||||
#!/bin/bash
|
||||
|
||||
# maintains a jump-list of the directories you actually use
|
||||
#
|
||||
# INSTALL:
|
||||
# * put something like this in your .bashrc:
|
||||
# . /path/to/z.sh
|
||||
# * cd around for a while to build up the db
|
||||
# * PROFIT!!
|
||||
#
|
||||
# USE:
|
||||
# * z foo # goes to most frecent dir matching foo
|
||||
# * z foo bar # goes to most frecent dir matching foo and bar
|
||||
# * z -r foo # goes to highest ranked dir matching foo
|
||||
# * z -t foo # goes to most recently accessed dir matching foo
|
||||
# * z -l foo # list all dirs matching foo (by frecency)
|
||||
|
||||
z() {
|
||||
local datafile="$HOME/.z"
|
||||
if [ "$1" = "--add" ]; then
|
||||
# add
|
||||
shift
|
||||
# $HOME isn't worth matching
|
||||
[ "$*" = "$HOME" ] && return
|
||||
awk -v p="$*" -v t="$(date +%s)" -F"|" '
|
||||
BEGIN { rank[p] = 1; time[p] = t }
|
||||
$2 >= 1 {
|
||||
if( $1 == p ) {
|
||||
rank[$1] = $2 + 1
|
||||
time[$1] = t
|
||||
} else {
|
||||
rank[$1] = $2
|
||||
time[$1] = $3
|
||||
}
|
||||
count += $2
|
||||
}
|
||||
END {
|
||||
if( count > 1000 ) {
|
||||
for( i in rank ) print i "|" 0.9*rank[i] "|" time[i] # aging
|
||||
} else for( i in rank ) print i "|" rank[i] "|" time[i]
|
||||
}
|
||||
' "$datafile" 2>/dev/null > "$datafile.tmp"
|
||||
mv -f "$datafile.tmp" "$datafile"
|
||||
elif [ "$1" = "--complete" ]; then
|
||||
# tab completion
|
||||
awk -v q="$2" -F"|" '
|
||||
BEGIN {
|
||||
if( q == tolower(q) ) nocase = 1
|
||||
split(substr(q,3),fnd," ")
|
||||
}
|
||||
{
|
||||
if( system("test -d \"" $1 "\"") ) next
|
||||
if( nocase ) {
|
||||
for( i in fnd ) tolower($1) !~ tolower(fnd[i]) && $1 = ""
|
||||
if( $1 ) print $1
|
||||
} else {
|
||||
for( i in fnd ) $1 !~ fnd[i] && $1 = ""
|
||||
if( $1 ) print $1
|
||||
}
|
||||
}
|
||||
' "$datafile" 2>/dev/null
|
||||
else
|
||||
# list/go
|
||||
while [ "$1" ]; do case "$1" in
|
||||
-h) echo "z [-h][-l][-r][-t] args" >&2; return;;
|
||||
-l) local list=1;;
|
||||
-r) local typ="rank";;
|
||||
-t) local typ="recent";;
|
||||
--) while [ "$1" ]; do shift; local fnd="$fnd $1";done;;
|
||||
*) local fnd="$fnd $1";;
|
||||
esac; local last=$1; shift; done
|
||||
[ "$fnd" ] || local list=1
|
||||
# if we hit enter on a completion just go there
|
||||
[ -d "$last" ] && cd "$last" && return
|
||||
[ -f "$datafile" ] || return
|
||||
local cd="$(awk -v t="$(date +%s)" -v list="$list" -v typ="$typ" -v q="$fnd" -v tmpfl="$datafile.tmp" -F"|" '
|
||||
function frecent(rank, time) {
|
||||
dx = t-time
|
||||
if( dx < 3600 ) return rank*4
|
||||
if( dx < 86400 ) return rank*2
|
||||
if( dx < 604800 ) return rank/2
|
||||
return rank/4
|
||||
}
|
||||
function output(files, toopen, override) {
|
||||
if( list ) {
|
||||
if( typ == "recent" ) {
|
||||
cmd = "sort -nr >&2"
|
||||
} else cmd = "sort -n >&2"
|
||||
for( i in files ) if( files[i] ) printf "%-10s %s\n", files[i], i | cmd
|
||||
if( override ) printf "%-10s %s\n", "common:", override > "/dev/stderr"
|
||||
} else {
|
||||
if( override ) toopen = override
|
||||
print toopen
|
||||
}
|
||||
}
|
||||
function common(matches, fnd, nc) {
|
||||
for( i in matches ) {
|
||||
if( matches[i] && (!short || length(i) < length(short)) ) short = i
|
||||
}
|
||||
if( short == "/" ) return
|
||||
for( i in matches ) if( matches[i] && i !~ short ) x = 1
|
||||
if( x ) return
|
||||
if( nc ) {
|
||||
for( i in fnd ) if( tolower(short) !~ tolower(fnd[i]) ) x = 1
|
||||
} else for( i in fnd ) if( short !~ fnd[i] ) x = 1
|
||||
if( !x ) return short
|
||||
}
|
||||
BEGIN { split(q, a, " ") }
|
||||
{
|
||||
if( system("test -d \"" $1 "\"") ) next
|
||||
print $0 >> tmpfl
|
||||
if( typ == "rank" ) {
|
||||
f = $2
|
||||
} else if( typ == "recent" ) {
|
||||
f = t-$3
|
||||
} else f = frecent($2, $3)
|
||||
wcase[$1] = nocase[$1] = f
|
||||
for( i in a ) {
|
||||
if( $1 !~ a[i] ) delete wcase[$1]
|
||||
if( tolower($1) !~ tolower(a[i]) ) delete nocase[$1]
|
||||
}
|
||||
if( wcase[$1] > oldf ) {
|
||||
cx = $1
|
||||
oldf = wcase[$1]
|
||||
} else if( nocase[$1] > noldf ) {
|
||||
ncx = $1
|
||||
noldf = nocase[$1]
|
||||
}
|
||||
}
|
||||
END {
|
||||
if( cx ) {
|
||||
output(wcase, cx, common(wcase, a, 0))
|
||||
} else if( ncx ) output(nocase, ncx, common(nocase, a, 1))
|
||||
}
|
||||
' "$datafile")"
|
||||
if [ $? -gt 0 ]; then
|
||||
rm -f "$datafile.tmp"
|
||||
else
|
||||
mv -f "$datafile.tmp" "$datafile"
|
||||
[ "$cd" ] && cd "$cd"
|
||||
fi
|
||||
fi
|
||||
}
|
||||
# tab completion
|
||||
complete -C 'z --complete "$COMP_LINE"' z
|
||||
# populate directory list. avoid clobbering other PROMPT_COMMANDs.
|
||||
echo $PROMPT_COMMAND | grep -q "z --add"
|
||||
[ $? -gt 0 ] && PROMPT_COMMAND='z --add "$(pwd -P)";'"$PROMPT_COMMAND"
|
||||
Reference in New Issue
Block a user