Skip to content

Instantly share code, notes, and snippets.

Created February 28, 2017 23:22
Show Gist options
  • Save anonymous/6eb874ca9475449b25831c4ba9a25331 to your computer and use it in GitHub Desktop.
Save anonymous/6eb874ca9475449b25831c4ba9a25331 to your computer and use it in GitHub Desktop.
example plumbing rules for plan 9 plumber
# plumbing rules
# update: ~/.plumbing | 9p write plumb/rules
# load default file addressing
# https://github.com/9fans/plan9port/blob/master/plumb/fileaddr
include fileaddr
# variables
editor = atom
filechars = '[a-zA-Z¡-￿0-9_/\-.'' ]+'
notechars = '[a-zA-Z¡-￿0-9_/\-'' ]+'
textchars = '[a-zA-Z¡-￿0-9_/\-.'' ]'
protocol = (http://|https://|file://|mailto:)
urlchars = '[a-zA-Z0-9_@\-]+([.:][a-zA-Z0-9_@\-]+)*/?[a-zA-Z0-9_?,%#~&/\-+=]+([:.][a-zA-Z0-9_?,%#~&/\-+=]+)*'
audiosuffix = (aac|flac|mp3|wav)
docsuffix = (doc|docx|ppt|pptx|xls|xlsx)
imagesuffix = (jpe?g|gif|png|svg|tiff?)
pdfsuffix = (eps|pdf|ps|dvi)
videosuffix = (avi|mkv|mp4|ogv|webm)
# rules
# these are generally in order from most specific to least,
# since first rule that fires wins.
# note link
# possibly tagged by linenumber:columnnumber or linenumber.columnnumber
type is text
data matches '🔗('$textchars'*'$textchars')':$twocolonaddr
arg isdir .
attr add addr=$2-#1+#$3
plumb start $editor $dir/$1.md:$2:$3
# note link
# possibly tagged by linenumber
type is text
data matches '🔗('$textchars'*'$textchars')('$addr')?'
arg isdir .
attr add addr=$3
plumb start $editor $dir/$1.md:$3
# @tags
type is text
data matches '@all'
arg isdir .
plumb start bash -c 'tf="$(mktemp /tmp/@all.XXX.md)" && echo -en "all @ tags\n" >> "$tf" && ag --markdown --nocolor --nofilename -o "(?<=^|(?<=[^.?\/[:alnum:]]))@([\w\-]+)" "'$dir'" | sort -u | sed "/@all/d" | cat >> "$tf" && '$editor' "$tf" && unset tf'
# #tags
type is text
data matches '#all'
arg isdir .
plumb start bash -c 'tf="$(mktemp /tmp/#all.XXX.md)" && echo -en "all # tags\n" >> "$tf" && ag --markdown --nocolor --nofilename -o "(?<=^|(?<=[^.?\/[:alnum:]]))#([\w\-]+)" "'$dir'" | sort -u | sed "/#all/d" | cat >> "$tf" && '$editor' "$tf" && unset tf'
# @tag link
type is text
data matches '@"?('$notechars')"?'
arg isdir .
plumb start bash -c 'tf="$(mktemp /tmp/@"'$1'".XXX.md)" && echo -en "notes tagged with @"'$1'"\nshow @all\n\n" >> "$tf" && ag -lS "@'$1'" "'$dir'" | sed "s:'$dir'/::g" | sort | cat >> "$tf" && '$editor' "$tf" && unset tf'
# #tag link
type is text
data matches '#"?('$notechars')"?'
arg isdir .
plumb start bash -c 'tf="$(mktemp /tmp/#"'$1'".XXX.md)" && echo -en "notes tagged with #"'$1'"\nshow #all\n\n" >> "$tf" && ag -lS "#'$1'" "'$dir'" | sed "s:'$dir'/::g" | sort | cat >> "$tf" && '$editor' "$tf" && unset tf'
# search link
type is text
data matches '\?"?('$notechars')"?'
arg isdir .
plumb start bash -c 'tf="$(mktemp /tmp/?"'$1'".XXX.md)" && echo -en "Search results for: "'$1'"\n\n" >> "$tf" && ag -S --column --group "'$1'" "'$dir'" | sed "s:'$dir'/::g" | cat >> "$tf" && '$editor' "$tf" && unset tf'
# url
type is text
data matches $protocol$urlchars
plumb start xdg-open $0
# audio
type is text
data matches $filechars
data matches '('$filechars')\.'$audiosuffix''
arg isfile $0
plumb start xdg-open $file
# image
type is text
data matches $filechars
data matches '('$filechars')\.'$imagesuffix''
arg isfile $0
plumb start xdg-open $file
# office
type is text
data matches $filechars
data matches '('$filechars')\.'$docsuffix''
arg isfile $0
plumb start xdg-open $file
# pdf
type is text
data matches $filechars
data matches '('$filechars')\.'$pdfsuffix''
arg isfile $0
plumb start xdg-open $file
# video
type is text
data matches $filechars
data matches '('$filechars')\.'$videosuffix''
arg isfile $0
plumb start xdg-open $file
# existing files
# tagged by linenumber:columnnumber or linenumber.columnnumber
type is text
data matches '('$textchars'*'$textchars')':$twocolonaddr
arg isfile $1
data set $file
attr add addr=$2-#1+#$3
plumb start $editor $file:$2:$3
# existing files
# possibly tagged by linenumber
type is text
data matches '('$textchars'*'$textchars')('$addr')?'
arg isfile $1
data set $file
attr add addr=$3
plumb start $editor $file:$3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment