Last active
April 26, 2016 13:59
-
-
Save lonetwin/0bc43ae3ae94ac6dfe7bc8e28b4d16ec to your computer and use it in GitHub Desktop.
Collection of bashrc functions (and their bash completions) I find useful
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# execute an interactive python shell on a remote machine, | |
# over ssh, after coping my local pythonrc to that machine | |
# (my pythonrc available here: https://gist.github.com/lonetwin/5902720) | |
function rpython { | |
DEST='/tmp/.pythonrc.py' | |
scp -q $PYTHONSTARTUP $1:$DEST | |
ssh -t $1 -- "PYTHONSTARTUP=$DEST python" | |
ssh $1 "rm $DEST" | |
} | |
# - setup completion for rpython | |
complete -F _known_hosts rpython | |
# mount remote directories using sshfs (https://github.com/libfuse/sshfs) | |
# by executing "sshfs host:/dest/path $HOME/src/sshfs/dest/path", | |
# creating the mountpoint, if necessary. If leading / in /dest/path is | |
# missing, the path is relative to ~ on the destination | |
function mount_sshfs { | |
local USAGE="Usage: mount_sshfs <hostname:[path]>" | |
[ $# -lt 1 ] && echo $USAGE && return | |
local srcpath="${1}" | |
local destdir="${HOME}/src/sshfs/${srcpath/:*/}" | |
[ -d "${destdir}" ] || mkdir -p "${destdir}" | |
sshfs "${srcpath}" "${destdir}" | |
} | |
complete -F _known_hosts -S: mount_sshfs | |
function isolate { | |
# - filter to select all lines starting with pattern in $1 upto the next | |
# newline or the pattern in $2 if provided. | |
# For example, | |
# $ cat /etc/passwd | isolate :500:500 :1000:1000 | |
# will print out all lines for uids between 500 and 1000 and | |
# $ cat /path/to/some_python_script.py | isolate 'def func_name' | |
# will print out the definition of 'func_name()' (assuming of course that | |
# the first line after the function definition is an empty line) | |
sed -n "/${1}/,/${2:-^\$}/p" | |
} | |
function pdfcompress { | |
# - reduce the size of a pdf file by re-writing it in lower resolution | |
# (default to the gs option -dPDFSETTINGS=/ebook) | |
local USAGE="USAGE: pdfcompress <inputfile> <outputfile> [<screen|ebook|printer|prepress>]" | |
[ $# -lt 2 ] && echo $USAGE && return | |
gs -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dPDFSETTINGS=/${3:-ebook} -sOutputFile=$2 $1 | |
} | |
complete -f -X '!*.pdf' pdfcompress |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment