Add bpst.rc script to easily create blog posts, it takes a single argument that is used as the post tile.
This commit is contained in:
parent
e90c9d5a67
commit
9f46f17090
1 changed files with 55 additions and 0 deletions
55
bin/bpst.rc
Executable file
55
bin/bpst.rc
Executable file
|
|
@ -0,0 +1,55 @@
|
|||
#!/usr/bin/env rc
|
||||
|
||||
path=( $PLAN9/bin $path )
|
||||
base=.
|
||||
|
||||
fn die {
|
||||
echo error: $* >[1=2]
|
||||
exit 1
|
||||
}
|
||||
|
||||
if (~ $#* 0)
|
||||
die 'Missing title'
|
||||
|
||||
if(~ $#user 0)
|
||||
user = `{whoami}
|
||||
|
||||
file = (); title = ();
|
||||
bloguser = $user
|
||||
while(! ~ $#* 0) {
|
||||
switch($1) {
|
||||
case -u
|
||||
base=/gsoc/www/people/$user/blog/
|
||||
shift
|
||||
case *
|
||||
title = $"*
|
||||
}
|
||||
shift
|
||||
}
|
||||
|
||||
date=`{/bin/date +%F}
|
||||
|
||||
n = 1
|
||||
for(f in $base/$date-*) {
|
||||
i = `{echo $f | sed -n 's|^.*/'$date'-([0-9]+)_.*|\1|p'}
|
||||
if(! ~ $#i 0 && test $i -ge $n)
|
||||
n = `{hoc -e $i'+1'}
|
||||
}
|
||||
|
||||
if(~ $EDITOR '')
|
||||
EDITOR = vi
|
||||
|
||||
file = $home/.blogtmp.$pid
|
||||
rm $file >[2]/dev/null
|
||||
touch $file
|
||||
$EDITOR $file
|
||||
ispell $file
|
||||
rm $file.bak >[2]/dev/null
|
||||
|
||||
|
||||
title = `{ echo $"title | sed 's/ /_/g' }
|
||||
|
||||
title = `{echo $"title | sed 's/[ ]+/_/g; 1q'}
|
||||
|
||||
mv $file $base/$"date^'-'^$"n^_$"title.md
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue