Merge 8e5f72856c into 54680bd83a
commit
7644939d93
504
lib/composure.sh
504
lib/composure.sh
|
|
@ -1,191 +1,27 @@
|
||||||
# composure - by erichs
|
# composure - by erichs
|
||||||
# light-hearted shell functions for intuitive shell programming
|
# light-hearted functions for intuitive shell programming
|
||||||
|
|
||||||
# install: source this script in your ~/.profile or ~/.${SHELL}rc script
|
# install: source this script in your ~/.profile or ~/.${SHELL}rc script
|
||||||
|
|
||||||
# latest source available at http://git.io/composure
|
# latest source available at http://git.io/composure
|
||||||
# known to work on bash, zsh, and ksh93
|
# known to work on bash, zsh, and ksh93
|
||||||
|
|
||||||
# define default metadata keywords:
|
# 'plumbing' functions
|
||||||
about () { :; }
|
|
||||||
group () { :; }
|
|
||||||
param () { :; }
|
|
||||||
author () { :; }
|
|
||||||
example () { :; }
|
|
||||||
|
|
||||||
cite ()
|
composure_keywords ()
|
||||||
{
|
{
|
||||||
about creates a new meta keyword for use in your functions
|
echo "about author example group param version"
|
||||||
param 1: keyword
|
|
||||||
example $ cite url
|
|
||||||
example $ url http://somewhere.com
|
|
||||||
group composure
|
|
||||||
|
|
||||||
# this is the storage half of the 'metadata' system:
|
|
||||||
# we create dynamic metadata keywords with function wrappers around
|
|
||||||
# the NOP command, ':'
|
|
||||||
|
|
||||||
# anything following a keyword will get parsed as a positional
|
|
||||||
# parameter, but stay resident in the ENV. As opposed to shell
|
|
||||||
# comments, '#', which do not get parsed, thus are not available
|
|
||||||
# at runtime.
|
|
||||||
|
|
||||||
# a BIG caveat--your metadata must be roughly parsable: do not use
|
|
||||||
# contractions, and consider single or double quoting if it contains
|
|
||||||
# non-alphanumeric characters
|
|
||||||
|
|
||||||
typeset keyword
|
|
||||||
for keyword in $*; do
|
|
||||||
eval "function $keyword { :; }"
|
|
||||||
done
|
|
||||||
}
|
|
||||||
|
|
||||||
draft ()
|
|
||||||
{
|
|
||||||
about wraps last command into a new function
|
|
||||||
param 1: name to give function
|
|
||||||
example $ ls
|
|
||||||
example $ draft list
|
|
||||||
example $ list
|
|
||||||
group composure
|
|
||||||
|
|
||||||
typeset func=$1
|
|
||||||
eval 'function ' $func ' { ' $(fc -ln -1) '; }'
|
|
||||||
typeset file=$(mktemp /tmp/draft.XXXX)
|
|
||||||
typeset -f $func > $file
|
|
||||||
transcribe $func $file draft
|
|
||||||
rm $file 2>/dev/null
|
|
||||||
}
|
|
||||||
|
|
||||||
glossary ()
|
|
||||||
{
|
|
||||||
about displays help summary for all functions, or summary for a group of functions
|
|
||||||
param 1: optional, group name
|
|
||||||
example $ glossary
|
|
||||||
example $ glossary misc
|
|
||||||
group composure
|
|
||||||
|
|
||||||
typeset targetgroup=${1:-}
|
|
||||||
|
|
||||||
for func in $(listfunctions); do
|
|
||||||
typeset about="$(metafor $func about)"
|
|
||||||
if [ -n "$targetgroup" ]; then
|
|
||||||
typeset group="$(metafor $func group)"
|
|
||||||
if [ "$group" != "$targetgroup" ]; then
|
|
||||||
continue # skip non-matching groups, if specified
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
letterpress "$about" $func
|
|
||||||
done
|
|
||||||
}
|
}
|
||||||
|
|
||||||
letterpress ()
|
letterpress ()
|
||||||
{
|
{
|
||||||
typeset metadata=$1 leftcol=${2:- } rightcol
|
typeset rightcol="$1" leftcol="${2:- }"
|
||||||
|
|
||||||
if [ -z "$metadata" ]; then
|
if [ -z "$rightcol" ]; then
|
||||||
return
|
return
|
||||||
fi
|
fi
|
||||||
|
|
||||||
OLD=$IFS; IFS=$'\n'
|
printf "%-20s%s\n" "$leftcol" "$rightcol"
|
||||||
for rightcol in $metadata; do
|
|
||||||
printf "%-20s%s\n" $leftcol $rightcol
|
|
||||||
done
|
|
||||||
IFS=$OLD
|
|
||||||
}
|
|
||||||
|
|
||||||
listfunctions ()
|
|
||||||
{
|
|
||||||
# unfortunately, there does not seem to be a easy, portable way to list just the
|
|
||||||
# names of the defined shell functions...
|
|
||||||
|
|
||||||
# here's a hack I modified from a StackOverflow post:
|
|
||||||
# we loop over the ps listing for the current process ($$), and print the last column (CMD)
|
|
||||||
# stripping any leading hyphens bash sometimes throws in there
|
|
||||||
|
|
||||||
typeset x ans
|
|
||||||
typeset this=$(for x in $(ps -p $$); do ans=$x; done; printf "%s\n" $ans | sed 's/^-*//')
|
|
||||||
case "$this" in
|
|
||||||
bash)
|
|
||||||
typeset -F | awk '{print $3}'
|
|
||||||
;;
|
|
||||||
*)
|
|
||||||
# trim everything following '()' in ksh
|
|
||||||
typeset +f | sed 's/().*$//'
|
|
||||||
;;
|
|
||||||
esac
|
|
||||||
}
|
|
||||||
|
|
||||||
metafor ()
|
|
||||||
{
|
|
||||||
about prints function metadata associated with keyword
|
|
||||||
param 1: function name
|
|
||||||
param 2: meta keyword
|
|
||||||
example $ metafor glossary example
|
|
||||||
group composure
|
|
||||||
typeset func=$1 keyword=$2
|
|
||||||
|
|
||||||
# this sed-fu is the retrieval half of the 'metadata' system:
|
|
||||||
# first 'cat' the function definition,
|
|
||||||
# then 'grep' for the metadata keyword, and
|
|
||||||
# then parse and massage the matching line
|
|
||||||
typeset -f $func | sed -n "s/;$//;s/^[ ]*$keyword \([^([].*\)*$/\1/p"
|
|
||||||
}
|
|
||||||
|
|
||||||
reference ()
|
|
||||||
{
|
|
||||||
about displays apidoc help for a specific function
|
|
||||||
param 1: function name
|
|
||||||
example $ reference revise
|
|
||||||
group composure
|
|
||||||
|
|
||||||
typeset func=$1
|
|
||||||
|
|
||||||
typeset about="$(metafor $func about)"
|
|
||||||
letterpress "$about" $func
|
|
||||||
|
|
||||||
typeset params="$(metafor $func param)"
|
|
||||||
if [ -n "$params" ]; then
|
|
||||||
printf "parameters:\n"
|
|
||||||
letterpress "$params"
|
|
||||||
fi
|
|
||||||
|
|
||||||
typeset examples="$(metafor $func example)"
|
|
||||||
if [ -n "$examples" ]; then
|
|
||||||
printf "examples:\n"
|
|
||||||
letterpress "$examples"
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
revise ()
|
|
||||||
{
|
|
||||||
about loads function into editor for revision
|
|
||||||
param 1: name of function
|
|
||||||
example $ revise myfunction
|
|
||||||
group composure
|
|
||||||
|
|
||||||
typeset func=$1
|
|
||||||
typeset temp=$(mktemp /tmp/revise.XXXX)
|
|
||||||
|
|
||||||
# populate tempfile...
|
|
||||||
if [ -f ~/.composure/$func.inc ]; then
|
|
||||||
# ...with contents of latest git revision...
|
|
||||||
cat ~/.composure/$func.inc >> $temp
|
|
||||||
else
|
|
||||||
# ...or from ENV if not previously versioned
|
|
||||||
typeset -f $func >> $temp
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [ -z "$EDITOR" ]
|
|
||||||
then
|
|
||||||
typeset EDITOR=vi
|
|
||||||
fi
|
|
||||||
|
|
||||||
$EDITOR $temp
|
|
||||||
source $temp
|
|
||||||
|
|
||||||
transcribe $func $temp revise
|
|
||||||
rm $temp
|
|
||||||
}
|
}
|
||||||
|
|
||||||
transcribe ()
|
transcribe ()
|
||||||
|
|
@ -246,6 +82,332 @@ transcribe ()
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
transcribe ()
|
||||||
|
{
|
||||||
|
typeset func=$1
|
||||||
|
typeset file=$2
|
||||||
|
typeset operation="$3"
|
||||||
|
|
||||||
|
if git --version >/dev/null 2>&1; then
|
||||||
|
if [ -d ~/.composure ]; then
|
||||||
|
(
|
||||||
|
cd ~/.composure
|
||||||
|
if git rev-parse 2>/dev/null; then
|
||||||
|
if [ ! -f $file ]; then
|
||||||
|
printf "%s\n" "Oops! Couldn't find $file to version it for you..."
|
||||||
|
return
|
||||||
|
fi
|
||||||
|
cp $file ~/.composure/$func.inc
|
||||||
|
git add --all .
|
||||||
|
git commit -m "$operation $func"
|
||||||
|
fi
|
||||||
|
)
|
||||||
|
else
|
||||||
|
if [ "$USE_COMPOSURE_REPO" = "0" ]; then
|
||||||
|
return # if you say so...
|
||||||
|
fi
|
||||||
|
printf "%s\n" "I see you don't have a ~/.composure repo..."
|
||||||
|
typeset input
|
||||||
|
typeset valid=0
|
||||||
|
while [ $valid != 1 ]; do
|
||||||
|
printf "\n%s" 'would you like to create one? y/n: '
|
||||||
|
read input
|
||||||
|
case $input in
|
||||||
|
y|yes|Y|Yes|YES)
|
||||||
|
(
|
||||||
|
echo 'creating git repository for your functions...'
|
||||||
|
mkdir ~/.composure
|
||||||
|
cd ~/.composure
|
||||||
|
git init
|
||||||
|
echo "composure stores your function definitions here" > README.txt
|
||||||
|
git add README.txt
|
||||||
|
git commit -m 'initial commit'
|
||||||
|
)
|
||||||
|
# if at first you don't succeed...
|
||||||
|
transcribe "$func" "$file" "$operation"
|
||||||
|
valid=1
|
||||||
|
;;
|
||||||
|
n|no|N|No|NO)
|
||||||
|
printf "%s\n" "ok. add 'export USE_COMPOSURE_REPO=0' to your startup script to disable this message."
|
||||||
|
valid=1
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
printf "%s\n" "sorry, didn't get that..."
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
typeset_functions ()
|
||||||
|
{
|
||||||
|
# unfortunately, there does not seem to be a easy, portable way to list just the
|
||||||
|
# names of the defined shell functions...
|
||||||
|
|
||||||
|
# here's a hack I modified from a StackOverflow post:
|
||||||
|
# we loop over the ps listing for the current process ($$), and print the last column (CMD)
|
||||||
|
# stripping any leading hyphens bash sometimes throws in there
|
||||||
|
|
||||||
|
typeset x ans
|
||||||
|
typeset this=$(for x in $(ps -p $$); do ans=$x; done; printf "%s\n" $ans | sed 's/^-*//')
|
||||||
|
typeset shell=$(basename $this) # e.g. /bin/bash => bash
|
||||||
|
case "$shell" in
|
||||||
|
bash)
|
||||||
|
typeset -F | awk '{print $3}'
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
# trim everything following '()' in ksh
|
||||||
|
typeset +f | sed 's/().*$//'
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
# bootstrap metadata keywords for porcelain functions
|
||||||
|
for f in $(composure_keywords)
|
||||||
|
do
|
||||||
|
eval "$f() { :; }"
|
||||||
|
done
|
||||||
|
unset f
|
||||||
|
|
||||||
|
|
||||||
|
# 'porcelain' functions
|
||||||
|
|
||||||
|
cite ()
|
||||||
|
{
|
||||||
|
about creates one or more meta keywords for use in your functions
|
||||||
|
param one or more keywords
|
||||||
|
example '$ cite url username'
|
||||||
|
example '$ url http://somewhere.com'
|
||||||
|
example '$ username alice'
|
||||||
|
group composure
|
||||||
|
|
||||||
|
# this is the storage half of the 'metadata' system:
|
||||||
|
# we create dynamic metadata keywords with function wrappers around
|
||||||
|
# the NOP command, ':'
|
||||||
|
|
||||||
|
# anything following a keyword will get parsed as a positional
|
||||||
|
# parameter, but stay resident in the ENV. As opposed to shell
|
||||||
|
# comments, '#', which do not get parsed and are not available
|
||||||
|
# at runtime.
|
||||||
|
|
||||||
|
# a BIG caveat--your metadata must be roughly parsable: do not use
|
||||||
|
# contractions, and consider single or double quoting if it contains
|
||||||
|
# non-alphanumeric characters
|
||||||
|
|
||||||
|
if [ -z "$1" ]; then
|
||||||
|
printf '%s\n' 'missing parameter(s)'
|
||||||
|
reference cite
|
||||||
|
return
|
||||||
|
fi
|
||||||
|
|
||||||
|
typeset keyword
|
||||||
|
for keyword in $*; do
|
||||||
|
eval "$keyword() { :; }"
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
|
draft ()
|
||||||
|
{
|
||||||
|
about wraps command from history into a new function, default is last command
|
||||||
|
param 1: name to give function
|
||||||
|
param 2: optional history line number
|
||||||
|
example '$ ls'
|
||||||
|
example '$ draft list'
|
||||||
|
example '$ draft newfunc 1120 # wraps command at history line 1120 in newfunc()'
|
||||||
|
group composure
|
||||||
|
|
||||||
|
typeset func=$1
|
||||||
|
typeset num=$2
|
||||||
|
typeset cmd
|
||||||
|
|
||||||
|
if [ -z "$func" ]; then
|
||||||
|
printf '%s\n' 'missing parameter(s)'
|
||||||
|
reference draft
|
||||||
|
return
|
||||||
|
fi
|
||||||
|
|
||||||
|
# aliases bind tighter than function names, disallow them
|
||||||
|
if [ -n "$(type -a $func | grep 'is.*alias')" ]; then
|
||||||
|
printf '%s\n' "sorry, $(type -a $func). please choose another name."
|
||||||
|
return
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ -z "$num" ]; then
|
||||||
|
# parse last command from fc output
|
||||||
|
# some versions of 'fix command, fc' need corrective lenses...
|
||||||
|
typeset myopic=$(fc -ln -1 | grep draft)
|
||||||
|
typeset lines=1
|
||||||
|
if [ -n "$myopic" ]; then
|
||||||
|
lines=2
|
||||||
|
fi
|
||||||
|
cmd=$(fc -ln -$lines | head -1 | sed 's/^[[:blank:]]*//')
|
||||||
|
else
|
||||||
|
# parse command from history line number
|
||||||
|
cmd=$(eval "history | grep '^[[:blank:]]*$num' | head -1" | sed 's/^[[:blank:][:digit:]]*//')
|
||||||
|
fi
|
||||||
|
eval "$func() { $cmd; }"
|
||||||
|
typeset file=$(mktemp /tmp/draft.XXXX)
|
||||||
|
typeset -f $func > $file
|
||||||
|
transcribe $func $file draft
|
||||||
|
rm $file 2>/dev/null
|
||||||
|
}
|
||||||
|
|
||||||
|
glossary ()
|
||||||
|
{
|
||||||
|
about displays help summary for all functions, or summary for a group of functions
|
||||||
|
param 1: optional, group name
|
||||||
|
example '$ glossary'
|
||||||
|
example '$ glossary misc'
|
||||||
|
group composure
|
||||||
|
|
||||||
|
typeset targetgroup=${1:-}
|
||||||
|
|
||||||
|
for func in $(typeset_functions); do
|
||||||
|
if [ -n "$targetgroup" ]; then
|
||||||
|
typeset group="$(typeset -f $func | metafor group)"
|
||||||
|
if [ "$group" != "$targetgroup" ]; then
|
||||||
|
continue # skip non-matching groups, if specified
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
typeset about="$(typeset -f $func | metafor about)"
|
||||||
|
letterpress "$about" $func
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
|
metafor ()
|
||||||
|
{
|
||||||
|
about prints function metadata associated with keyword
|
||||||
|
param 1: meta keyword
|
||||||
|
example '$ typeset -f glossary | metafor example'
|
||||||
|
group composure
|
||||||
|
|
||||||
|
typeset keyword=$1
|
||||||
|
|
||||||
|
if [ -z "$keyword" ]; then
|
||||||
|
printf '%s\n' 'missing parameter(s)'
|
||||||
|
reference metafor
|
||||||
|
return
|
||||||
|
fi
|
||||||
|
|
||||||
|
# this sed-fu is the retrieval half of the 'metadata' system:
|
||||||
|
# 'grep' for the metadata keyword, and then parse/filter the matching line
|
||||||
|
|
||||||
|
# grep keyword # strip trailing '|"|; # ignore thru keyword and leading '|"
|
||||||
|
sed -n "/$keyword / s/['\";]*$//;s/^[ ]*$keyword ['\"]*\([^([].*\)*$/\1/p"
|
||||||
|
}
|
||||||
|
|
||||||
|
reference ()
|
||||||
|
{
|
||||||
|
about displays apidoc help for a specific function
|
||||||
|
param 1: function name
|
||||||
|
example '$ reference revise'
|
||||||
|
group composure
|
||||||
|
|
||||||
|
typeset func=$1
|
||||||
|
if [ -z "$func" ]; then
|
||||||
|
printf '%s\n' 'missing parameter(s)'
|
||||||
|
reference reference
|
||||||
|
return
|
||||||
|
fi
|
||||||
|
|
||||||
|
typeset line
|
||||||
|
|
||||||
|
typeset about="$(typeset -f $func | metafor about)"
|
||||||
|
letterpress "$about" $func
|
||||||
|
|
||||||
|
typeset author="$(typeset -f $func | metafor author)"
|
||||||
|
if [ -n "$author" ]; then
|
||||||
|
letterpress "$author" 'author:'
|
||||||
|
fi
|
||||||
|
|
||||||
|
typeset version="$(typeset -f $func | metafor version)"
|
||||||
|
if [ -n "$version" ]; then
|
||||||
|
letterpress "$version" 'version:'
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ -n "$(typeset -f $func | metafor param)" ]; then
|
||||||
|
printf "parameters:\n"
|
||||||
|
typeset -f $func | metafor param | while read line
|
||||||
|
do
|
||||||
|
letterpress "$line"
|
||||||
|
done
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ -n "$(typeset -f $func | metafor example)" ]; then
|
||||||
|
printf "examples:\n"
|
||||||
|
typeset -f $func | metafor example | while read line
|
||||||
|
do
|
||||||
|
letterpress "$line"
|
||||||
|
done
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
revise ()
|
||||||
|
{
|
||||||
|
about loads function into editor for revision
|
||||||
|
param 1: name of function
|
||||||
|
example '$ revise myfunction'
|
||||||
|
group composure
|
||||||
|
|
||||||
|
typeset func=$1
|
||||||
|
typeset temp=$(mktemp /tmp/revise.XXXX)
|
||||||
|
|
||||||
|
if [ -z "$func" ]; then
|
||||||
|
printf '%s\n' 'missing parameter(s)'
|
||||||
|
reference revise
|
||||||
|
return
|
||||||
|
fi
|
||||||
|
|
||||||
|
# populate tempfile...
|
||||||
|
if [ -f ~/.composure/$func.inc ]; then
|
||||||
|
# ...with contents of latest git revision...
|
||||||
|
cat ~/.composure/$func.inc >> $temp
|
||||||
|
else
|
||||||
|
# ...or from ENV if not previously versioned
|
||||||
|
typeset -f $func >> $temp
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ -z "$EDITOR" ]
|
||||||
|
then
|
||||||
|
typeset EDITOR=vi
|
||||||
|
fi
|
||||||
|
|
||||||
|
$EDITOR $temp
|
||||||
|
. $temp # source edited file
|
||||||
|
|
||||||
|
transcribe $func $temp revise
|
||||||
|
rm $temp
|
||||||
|
}
|
||||||
|
|
||||||
|
write ()
|
||||||
|
{
|
||||||
|
about writes one or more composed function definitions to stdout
|
||||||
|
param one or more function names
|
||||||
|
example '$ write finddown foo'
|
||||||
|
example '$ write finddown'
|
||||||
|
group composure
|
||||||
|
|
||||||
|
if [ -z "$1" ]; then
|
||||||
|
printf '%s\n' 'missing parameter(s)'
|
||||||
|
reference write
|
||||||
|
return
|
||||||
|
fi
|
||||||
|
|
||||||
|
# bootstrap metadata
|
||||||
|
cat <<END
|
||||||
|
for f in $(composure_keywords)
|
||||||
|
do
|
||||||
|
eval "\$f() { :; }"
|
||||||
|
done
|
||||||
|
unset f
|
||||||
|
END
|
||||||
|
|
||||||
|
# include cite() to enable custom keywords
|
||||||
|
typeset -f cite $*
|
||||||
|
}
|
||||||
|
|
||||||
: <<EOF
|
: <<EOF
|
||||||
License: The MIT License
|
License: The MIT License
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,9 @@
|
||||||
#
|
#
|
||||||
# [issue 108]: https://github.com/revans/bash-it/issues/108
|
# [issue 108]: https://github.com/revans/bash-it/issues/108
|
||||||
|
|
||||||
|
cite about-plugin
|
||||||
|
about-plugin 'automatically set your xterm title with host and location info'
|
||||||
|
|
||||||
set_xterm_title () {
|
set_xterm_title () {
|
||||||
local title="$1"
|
local title="$1"
|
||||||
echo -ne "\e]0;$title\007"
|
echo -ne "\e]0;$title\007"
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,12 @@
|
||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
# For generic functions.
|
cite about-plugin
|
||||||
|
about-plugin generic and miscellaneous tools
|
||||||
|
|
||||||
ips ()
|
ips ()
|
||||||
{
|
{
|
||||||
about display all ip addresses for this host
|
about display all ip addresses for this host
|
||||||
|
group base
|
||||||
ifconfig | grep "inet " | awk '{ print $2 }'
|
ifconfig | grep "inet " | awk '{ print $2 }'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -13,12 +15,14 @@ down4me ()
|
||||||
about checks whether a website is down for you, or everybody
|
about checks whether a website is down for you, or everybody
|
||||||
param 1: website url
|
param 1: website url
|
||||||
example '$ down4me http://www.google.com'
|
example '$ down4me http://www.google.com'
|
||||||
|
group base
|
||||||
curl -s "http://www.downforeveryoneorjustme.com/$1" | sed '/just you/!d;s/<[^>]*>//g'
|
curl -s "http://www.downforeveryoneorjustme.com/$1" | sed '/just you/!d;s/<[^>]*>//g'
|
||||||
}
|
}
|
||||||
|
|
||||||
myip ()
|
myip ()
|
||||||
{
|
{
|
||||||
about displays your ip address, as seen by the Internet
|
about displays your ip address, as seen by the Internet
|
||||||
|
group base
|
||||||
res=$(curl -s checkip.dyndns.org | grep -Eo '[0-9\.]+')
|
res=$(curl -s checkip.dyndns.org | grep -Eo '[0-9\.]+')
|
||||||
echo -e "Your public IP is: ${echo_bold_green} $res ${echo_normal}"
|
echo -e "Your public IP is: ${echo_bold_green} $res ${echo_normal}"
|
||||||
}
|
}
|
||||||
|
|
@ -29,6 +33,7 @@ pickfrom ()
|
||||||
about picks random line from file
|
about picks random line from file
|
||||||
param 1: filename
|
param 1: filename
|
||||||
example '$ pickfrom /usr/share/dict/words'
|
example '$ pickfrom /usr/share/dict/words'
|
||||||
|
group base
|
||||||
local file=$1
|
local file=$1
|
||||||
[ -z "$file" ] && reference $FUNCNAME && return
|
[ -z "$file" ] && reference $FUNCNAME && return
|
||||||
length=$(cat $file | wc -l)
|
length=$(cat $file | wc -l)
|
||||||
|
|
@ -43,6 +48,7 @@ pass ()
|
||||||
param if unset, defaults to 4
|
param if unset, defaults to 4
|
||||||
example '$ pass'
|
example '$ pass'
|
||||||
example '$ pass 6'
|
example '$ pass 6'
|
||||||
|
group base
|
||||||
local i pass length=${1:-4}
|
local i pass length=${1:-4}
|
||||||
pass=$(echo $(for i in $(eval echo "{1..$length}"); do pickfrom /usr/share/dict/words; done))
|
pass=$(echo $(for i in $(eval echo "{1..$length}"); do pickfrom /usr/share/dict/words; done))
|
||||||
echo "With spaces (easier to memorize): $pass"
|
echo "With spaces (easier to memorize): $pass"
|
||||||
|
|
@ -54,6 +60,7 @@ pmdown ()
|
||||||
about preview markdown file in a browser
|
about preview markdown file in a browser
|
||||||
param 1: markdown file
|
param 1: markdown file
|
||||||
example '$ pmdown README.md'
|
example '$ pmdown README.md'
|
||||||
|
group base
|
||||||
if command -v markdown &>/dev/null
|
if command -v markdown &>/dev/null
|
||||||
then
|
then
|
||||||
markdown $1 | browser
|
markdown $1 | browser
|
||||||
|
|
@ -68,6 +75,7 @@ mkcd ()
|
||||||
param path to create
|
param path to create
|
||||||
example '$ mkcd foo'
|
example '$ mkcd foo'
|
||||||
example '$ mkcd /tmp/img/photos/large'
|
example '$ mkcd /tmp/img/photos/large'
|
||||||
|
group base
|
||||||
mkdir -p "$*"
|
mkdir -p "$*"
|
||||||
cd "$*"
|
cd "$*"
|
||||||
}
|
}
|
||||||
|
|
@ -75,6 +83,7 @@ mkcd ()
|
||||||
lsgrep ()
|
lsgrep ()
|
||||||
{
|
{
|
||||||
about search through directory contents with grep
|
about search through directory contents with grep
|
||||||
|
group base
|
||||||
ls | grep "$*"
|
ls | grep "$*"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -84,6 +93,7 @@ pman ()
|
||||||
about view man documentation in Preview
|
about view man documentation in Preview
|
||||||
param 1: man page to view
|
param 1: man page to view
|
||||||
example '$ pman bash'
|
example '$ pman bash'
|
||||||
|
group base
|
||||||
man -t "${1}" | open -f -a $PREVIEW
|
man -t "${1}" | open -f -a $PREVIEW
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -93,6 +103,7 @@ pcurl ()
|
||||||
about download file and Preview it
|
about download file and Preview it
|
||||||
param 1: download URL
|
param 1: download URL
|
||||||
example '$ pcurl http://www.irs.gov/pub/irs-pdf/fw4.pdf'
|
example '$ pcurl http://www.irs.gov/pub/irs-pdf/fw4.pdf'
|
||||||
|
group base
|
||||||
curl "${1}" | open -f -a $PREVIEW
|
curl "${1}" | open -f -a $PREVIEW
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -101,17 +112,21 @@ pri ()
|
||||||
about display information about Ruby classes, modules, or methods, in Preview
|
about display information about Ruby classes, modules, or methods, in Preview
|
||||||
param 1: Ruby method, module, or class
|
param 1: Ruby method, module, or class
|
||||||
example '$ pri Array'
|
example '$ pri Array'
|
||||||
|
group base
|
||||||
ri -T "${1}" | open -f -a $PREVIEW
|
ri -T "${1}" | open -f -a $PREVIEW
|
||||||
}
|
}
|
||||||
|
|
||||||
quiet ()
|
quiet ()
|
||||||
{
|
{
|
||||||
|
about 'what *does* this do?'
|
||||||
|
group base
|
||||||
$* &> /dev/null &
|
$* &> /dev/null &
|
||||||
}
|
}
|
||||||
|
|
||||||
banish-cookies ()
|
banish-cookies ()
|
||||||
{
|
{
|
||||||
about redirect .adobe and .macromedia files to /dev/null
|
about redirect .adobe and .macromedia files to /dev/null
|
||||||
|
group base
|
||||||
rm -r ~/.macromedia ~/.adobe
|
rm -r ~/.macromedia ~/.adobe
|
||||||
ln -s /dev/null ~/.adobe
|
ln -s /dev/null ~/.adobe
|
||||||
ln -s /dev/null ~/.macromedia
|
ln -s /dev/null ~/.macromedia
|
||||||
|
|
@ -121,6 +136,7 @@ usage ()
|
||||||
{
|
{
|
||||||
about disk usage per directory, in Mac OS X and Linux
|
about disk usage per directory, in Mac OS X and Linux
|
||||||
param 1: directory name
|
param 1: directory name
|
||||||
|
group base
|
||||||
if [ $(uname) = "Darwin" ]; then
|
if [ $(uname) = "Darwin" ]; then
|
||||||
if [ -n $1 ]; then
|
if [ -n $1 ]; then
|
||||||
du -hd $1
|
du -hd $1
|
||||||
|
|
@ -142,6 +158,7 @@ t ()
|
||||||
about one thing todo
|
about one thing todo
|
||||||
param if not set, display todo item
|
param if not set, display todo item
|
||||||
param 1: todo text
|
param 1: todo text
|
||||||
|
group base
|
||||||
if [[ "$*" == "" ]] ; then
|
if [[ "$*" == "" ]] ; then
|
||||||
cat ~/.t
|
cat ~/.t
|
||||||
else
|
else
|
||||||
|
|
@ -154,25 +171,23 @@ command_exists ()
|
||||||
about checks for existence of a command
|
about checks for existence of a command
|
||||||
param 1: command to check
|
param 1: command to check
|
||||||
example '$ command_exists ls && echo exists'
|
example '$ command_exists ls && echo exists'
|
||||||
|
group base
|
||||||
type "$1" &> /dev/null ;
|
type "$1" &> /dev/null ;
|
||||||
}
|
}
|
||||||
|
|
||||||
plugins-help ()
|
plugins-help ()
|
||||||
{
|
{
|
||||||
about list all plugins and functions defined by bash-it
|
about list all plugins and functions defined by bash-it
|
||||||
echo "bash-it Plugins Help-Message"
|
group base
|
||||||
echo
|
printf '%s\n' "bash-it plugins help"
|
||||||
|
printf '\n'
|
||||||
set | grep "()" \
|
typeset group
|
||||||
| sed -e "/^_/d" | grep -v "BASH_ARGC=()" \
|
for group in $(all_groups)
|
||||||
| sed -e "/^\s/d" | grep -v "BASH_LINENO=()" \
|
do
|
||||||
| grep -v "BASH_ARGV=()" \
|
printf '%s\n' "group: $group"
|
||||||
| grep -v "BASH_SOURCE=()" \
|
glossary $group
|
||||||
| grep -v "DIRSTACK=()" \
|
printf '\n'
|
||||||
| grep -v "GROUPS=()" \
|
done
|
||||||
| grep -v "BASH_CMDS=()" \
|
|
||||||
| grep -v "BASH_ALIASES=()" \
|
|
||||||
| grep -v "COMPREPLY=()" | sed -e "s/()//"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
# useful for administrators and configs
|
# useful for administrators and configs
|
||||||
|
|
@ -180,7 +195,34 @@ buf ()
|
||||||
{
|
{
|
||||||
about back up file with timestamp
|
about back up file with timestamp
|
||||||
param filename
|
param filename
|
||||||
|
group base
|
||||||
local filename=$1
|
local filename=$1
|
||||||
local filetime=$(date +%Y%m%d_%H%M%S)
|
local filetime=$(date +%Y%m%d_%H%M%S)
|
||||||
cp ${filename} ${filename}_${filetime}
|
cp ${filename} ${filename}_${filetime}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
all_groups ()
|
||||||
|
{
|
||||||
|
about displays all unique metadata groups
|
||||||
|
group base
|
||||||
|
typeset func
|
||||||
|
typeset file=$(mktemp /tmp/composure.XXXX)
|
||||||
|
for func in $(typeset_functions)
|
||||||
|
do
|
||||||
|
typeset -f $func | metafor group >> $file
|
||||||
|
done
|
||||||
|
cat $file | sort | uniq
|
||||||
|
rm $file
|
||||||
|
}
|
||||||
|
|
||||||
|
available_plugins ()
|
||||||
|
{
|
||||||
|
about summarizes available bash_it plugins
|
||||||
|
group base
|
||||||
|
|
||||||
|
typeset f
|
||||||
|
for f in $BASH_IT/plugins/available/*.bash
|
||||||
|
do
|
||||||
|
letterpress "$(cat $f | metafor about-plugin)" "$(basename $f | cut -d'.' -f1)"
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,12 @@
|
||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
cite about-plugin
|
||||||
|
about-plugin query and display info about your battery charge level
|
||||||
|
|
||||||
battery_percentage(){
|
battery_percentage(){
|
||||||
|
about 'displays battery charge as a percentage of full (100%)'
|
||||||
|
group battery
|
||||||
|
|
||||||
if command_exists acpi;
|
if command_exists acpi;
|
||||||
then
|
then
|
||||||
local ACPI_OUTPUT=$(acpi -b)
|
local ACPI_OUTPUT=$(acpi -b)
|
||||||
|
|
@ -65,6 +71,9 @@ battery_percentage(){
|
||||||
}
|
}
|
||||||
|
|
||||||
battery_charge(){
|
battery_charge(){
|
||||||
|
about graphical display of your battery charge
|
||||||
|
group battery
|
||||||
|
|
||||||
# Full char
|
# Full char
|
||||||
local F_C='▸'
|
local F_C='▸'
|
||||||
# Depleted char
|
# Depleted char
|
||||||
|
|
|
||||||
|
|
@ -1,25 +1,20 @@
|
||||||
# based on https://gist.github.com/318247
|
# based on https://gist.github.com/318247
|
||||||
|
|
||||||
# Usage: browser
|
cite about-plugin
|
||||||
# pipe html to a browser
|
about-plugin 'render commandline output in your browser'
|
||||||
# e.g.
|
|
||||||
# $ echo "<h1>hi mom!</h1>" | browser
|
|
||||||
# $ ron -5 man/rip.5.ron | browser
|
|
||||||
|
|
||||||
function browser() {
|
function browser() {
|
||||||
|
about pipe html to a browser
|
||||||
|
example '$ echo "<h1>hi mom!</h1>" | browser'
|
||||||
|
example '$ ron -5 man/rip.5.ron | browser'
|
||||||
|
group browser
|
||||||
|
|
||||||
if [ -t 0 ]; then
|
if [ -t 0 ]; then
|
||||||
if [ -n "$1" ]; then
|
if [ -n "$1" ]; then
|
||||||
open $1
|
open $1
|
||||||
else
|
else
|
||||||
cat <<usage
|
reference browser
|
||||||
Usage: browser
|
fi
|
||||||
pipe html to a browser
|
|
||||||
|
|
||||||
$ echo '<h1>hi mom!</h1>' | browser
|
|
||||||
$ ron -5 man/rip.5.ron | browser
|
|
||||||
usage
|
|
||||||
|
|
||||||
fi
|
|
||||||
|
|
||||||
else
|
else
|
||||||
f="/tmp/browser.$RANDOM.html"
|
f="/tmp/browser.$RANDOM.html"
|
||||||
|
|
@ -29,14 +24,11 @@ usage
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
# 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() {
|
function wmate() {
|
||||||
|
about 'pipe hot spicy interwebs into textmate and cleanup!'
|
||||||
|
example '$ wmate google.com'
|
||||||
|
group browser
|
||||||
|
|
||||||
if [ -t 0 ]; then
|
if [ -t 0 ]; then
|
||||||
if [ -n "$1" ]; then
|
if [ -n "$1" ]; then
|
||||||
wget -qO- $1 | /usr/bin/mate
|
wget -qO- $1 | /usr/bin/mate
|
||||||
|
|
@ -64,34 +56,21 @@ end tell
|
||||||
EOT`
|
EOT`
|
||||||
|
|
||||||
else
|
else
|
||||||
cat <<usage
|
reference wmate
|
||||||
Usage: wmate google.com
|
|
||||||
wget into a pipe into TextMate and force Tidy (you can undo in textmate)
|
|
||||||
|
|
||||||
$ wmate google.com
|
|
||||||
usage
|
|
||||||
|
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
#
|
|
||||||
# Usage: raw google.com
|
|
||||||
# wget into a temp file and pump it into your browser
|
|
||||||
#
|
|
||||||
# e.g.
|
|
||||||
# $ raw google.com
|
|
||||||
function raw() {
|
function raw() {
|
||||||
|
about 'write wget into a temp file and pump it into your browser'
|
||||||
|
example '$ raw google.com'
|
||||||
|
group browser
|
||||||
|
|
||||||
if [ -t 0 ]; then
|
if [ -t 0 ]; then
|
||||||
if [ -n "$1" ]; then
|
if [ -n "$1" ]; then
|
||||||
wget -qO- $1 | browser
|
wget -qO- $1 | browser
|
||||||
else
|
else
|
||||||
cat <<usage
|
reference raw
|
||||||
Usage: raw google.com
|
fi
|
||||||
wget into a temp file and pump it into your browser
|
|
||||||
|
|
||||||
$ raw google.com
|
|
||||||
usage
|
|
||||||
fi
|
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue