2013-01-22

How to determine if current buffer is tramp buffer in Emacs

Tramp is Emacs' way to access remote files, e.g. via SSH. To determine if the current buffer is accessing a tramp file (e.g. to not try to run gtags or similar), try this:
(not (tramp-tramp-file-p (buffer-file-name (current-buffer))))

2013-01-08

Quoting a set of parameters for program arguments using sed

I have a script which launches another program. That program takes some command line arguments, which in turn can have parameters. Those parameters may include ";", which has a special meaning in the Bash. To quote these, you can use the following sed command:
$ echo "foo --bar=1 --baz=2" | sed -e 's/\(--[^[:space:]]*=\)\([^[:space:]]*\)/\1"\2"/g'
foo --bar="1" --baz="2"