summary refs log tree commit diff stats
path: root/examples/bash_automatic_cd.sh
Commit message (Collapse)AuthorAgeFilesLines
* Add correct path to ranger on OS XArshia Mufti2016-09-061-0/+2
|
* Fix mktemp invocation to work on Mac OS X and LinuxJesse Byler2015-06-101-1/+1
| | | | | | | | | | | mktemp on Mac OS X (and probably all BSDs) just returns an error when invoked without any arguments. The -t option used in this change is interpreted differently on Mac OS X and Linux, and is deprecated on Linux, but this invocation works as expected on both. See discussion at https://unix.stackexchange.com/questions/30091 Another alternative would be to use Python's tempfile module: https://docs.python.org/2/library/tempfile.html
* Should I dual ranger/cleric or wait for the THAC0 bonus? v1.7.0hut2015-04-141-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Squashed commit of the following: commit 7236dde27bf33fec5097c223f0d70598b10ba05f Author: hut <hut@lepus.uberspace.de> Date: Mon Apr 13 14:33:59 2015 +0200 wrote changelog entry commit 73e76b0f9a22ad8122154c4a2763c27ebce9be37 Author: hut <hut@lepus.uberspace.de> Date: Mon Apr 13 13:41:27 2015 +0200 update version number in man page commit b1948b9382027ed55d095a936610bc62f7cdba9a Author: hut <hut@lepus.uberspace.de> Date: Mon Apr 13 13:41:08 2015 +0200 update rifle version number commit a96a8a808a3c68eb848a3e0361fd95cb8c643d59 Author: hut <hut@lepus.uberspace.de> Date: Mon Apr 13 13:34:59 2015 +0200 s/ranger-master/ranger-stable/ commit 6967a48193227b4a0c843e8831e5511005179f69 Author: hut <hut@lepus.uberspace.de> Date: Mon Apr 13 13:33:06 2015 +0200 updated version number commit 0cbc401fd25fc4d307d026628e12ef1106a42bdf Author: hut <hut@lepus.uberspace.de> Date: Mon Apr 13 13:18:26 2015 +0200 updated version info in example plugins
* moved "doc/examples" to "examples" for more visibilityhut2015-04-131-0/+21
|
* move examples to doc/exampleshut2013-03-091-21/+0
|
* Added version info to exampleshut2013-03-011-0/+2
|
* added the examples from the man page to the examples directoryhut2012-08-061-0/+19
I guess a whole directory for examples scales better than having them in the man page.
.highlight .m { color: #0000DD; font-weight: bold } /* Literal.Number */ .highlight .s { color: #dd2200; background-color: #fff0f0 } /* Literal.String */ .highlight .na { color: #336699 } /* Name.Attribute */ .highlight .nb { color: #003388 } /* Name.Builtin */ .highlight .nc { color: #bb0066; font-weight: bold } /* Name.Class */ .highlight .no { color: #003366; font-weight: bold } /* Name.Constant */ .highlight .nd { color: #555555 } /* Name.Decorator */ .highlight .ne { color: #bb0066; font-weight: bold } /* Name.Exception */ .highlight .nf { color: #0066bb; font-weight: bold } /* Name.Function */ .highlight .nl { color: #336699; font-style: italic } /* Name.Label */ .highlight .nn { color: #bb0066; font-weight: bold } /* Name.Namespace */ .highlight .py { color: #336699; font-weight: bold } /* Name.Property */ .highlight .nt { color: #bb0066; font-weight: bold } /* Name.Tag */ .highlight .nv { color: #336699 } /* Name.Variable */ .highlight .ow { color: #008800 } /* Operator.Word */ .highlight .w { color: #bbbbbb } /* Text.Whitespace */ .highlight .mb { color: #0000DD; font-weight: bold } /* Literal.Number.Bin */ .highlight .mf { color: #0000DD; font-weight: bold } /* Literal.Number.Float */ .highlight .mh { color: #0000DD; font-weight: bold } /* Literal.Number.Hex */ .highlight .mi { color: #0000DD; font-weight: bold } /* Literal.Number.Integer */ .highlight .mo { color: #0000DD; font-weight: bold } /* Literal.Number.Oct */ .highlight .sa { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Affix */ .highlight .sb { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Backtick */ .highlight .sc { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Char */ .highlight .dl { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Delimiter */ .highlight .sd { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Doc */ .highlight .s2 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Double */ .highlight .se { color: #0044dd; background-color: #fff0f0 } /* Literal.String.Escape */ .highlight .sh { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Heredoc */ .highlight .si { color: #3333bb; background-color: #fff0f0 } /* Literal.String.Interpol */ .highlight .sx { color: #22bb22; background-color: #f0fff0 } /* Literal.String.Other */ .highlight .sr { color: #008800; background-color: #fff0ff } /* Literal.String.Regex */ .highlight .s1 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Single */ .highlight .ss { color: #aa6600; background-color: #fff0f0 } /* Literal.String.Symbol */ .highlight .bp { color: #003388 } /* Name.Builtin.Pseudo */ .highlight .fm { color: #0066bb; font-weight: bold } /* Name.Function.Magic */ .highlight .vc { color: #336699 } /* Name.Variable.Class */ .highlight .vg { color: #dd7700 } /* Name.Variable.Global */ .highlight .vi { color: #3333bb } /* Name.Variable.Instance */ .highlight .vm { color: #336699 } /* Name.Variable.Magic */ .highlight .il { color: #0000DD; font-weight: bold } /* Literal.Number.Integer.Long */
\ 2022 - winduptoy.sensorstation.co
\ PUBLIC DOMAIN

\ USAGE
\ $ cat in.gmi | gforth gmi2html.fs > out.html
\
\ This only outputs major blocks, allowing full customization of the HTML document.
\ Best used in composition, like so:
\ 
\ $ cat _header.html > out.html
\ $	cat in.gmi | gforth gmi2html.fs >> out.html
\ $ cat _footer.html >> out.html

\ === HTML Output === \

\ : html-line-break ." <br>" ;

: html-line-break ." " ;
: html-blockquote-open ." <blockquote>" ;
: html-blockquote-close ." </blockquote>" ;

: html-preformatted-open ( c-content u -- )
	.\" <pre aria-label=\"" type .\" \">" cr ;

: html-preformatted-close ." </pre>" cr ;

: html-list-open ." <ul>" ;
: html-list-close ." </ul>" ;

: html-paragraph-open ." <p>" ;
: html-paragraph-close ." </p>" ;

: html-list-item ( c-content u -- )
	." <li>" type ." </li>" ;


: html-link ( c-content u c-url u -- )
	.\" <p><a rel=\"noreferrer\" href=\"" type .\" \">"
	type
	." </a></p>"
	;

: html-heading ( level c-content u -- )
	." <h" 2 pick 48 + emit ." >"
	type
	." </h" 48 + emit ." >"
	;

\ === Parsing === \

: starts-preformatted? ( c-addr u -- f )
	s" ```" string-prefix? ;

: starts-blockquote? ( c-addr u -- f )
	s" >" string-prefix? ;

: starts-list-item? ( c-addr u -- f )
	s" *" string-prefix? ;

: starts-link? ( c-addr u -- f )
	s" =>" string-prefix? ;

: starts-heading? ( c-addr u -- n ) \ returns header level
	0 rot rot
	3 min 0 ?do
		dup i + c@ '# = if swap 1 + swap endif
	loop drop ;

4096 constant line-buffer-size
create   line-buffer line-buffer-size chars allot
variable line-number
variable line-len

0 constant capture-none
1 constant capture-preformatted
2 constant capture-blockquote
3 constant capture-list
variable capture-state

: process-line ( -- )
	capture-state @ case
		capture-preformatted of
			line-buffer line-len @ starts-preformatted? if
				html-preformatted-close
				capture-none capture-state !
				exit
			else
				line-buffer line-len @ type cr
				exit
			endif
		endof
		capture-blockquote of
			line-buffer line-len @ starts-blockquote? invert if
				html-blockquote-close
				capture-none capture-state !
			endif
		endof
		capture-list of
			line-buffer line-len @ starts-list-item? invert if
				html-list-close
				capture-none capture-state !
			endif
		endof
	endcase

	line-buffer line-len @ starts-preformatted? if
		capture-preformatted capture-state !
		line-buffer line-len @ '` skip
		html-preformatted-open
		exit
	endif

	line-buffer line-len @ starts-blockquote? if
		capture-state @ capture-blockquote = invert if
			html-blockquote-open
			capture-blockquote capture-state !
		endif
		line-buffer 1 + line-len @ 1 - type
		html-line-break cr
		exit
	endif
	line-buffer line-len @ starts-list-item? if
		capture-state @ capture-list = invert if
			html-list-open
			capture-list capture-state !
		endif
		line-buffer 1 + line-len @ 1 - html-list-item cr
		exit
	endif

	line-buffer line-len @ starts-heading? dup if
		line-buffer line-len @ '# skip 32 skip 9 skip html-heading cr
		exit
	endif drop

	line-buffer line-len @ starts-link? if
		line-buffer line-len @ '= skip '> skip 32 skip 9 skip ( c-addr len )

		\ find end of URL
		over over 32 scan ( c-addr len label-addr label-len )
		>r dup >r 2 pick - swap drop ( c-addr url-len )
		r> r> 32 skip 9 skip ( c-addr url-len label-addr label-len )
		dup 0 = if \ use the URL for the label if no label is provided
			drop drop over over
		endif

		2swap
		html-link

		exit
	endif

	line-len @ 0 = if
		html-line-break cr
	else
		html-paragraph-open
		line-buffer line-len @ type
		html-paragraph-close cr
	endif
	;

: gmi-to-html
	begin
		1 line-number +!
		line-buffer line-buffer-size stdin read-line ( len flag err )
		throw
		invert if drop exit endif  \ false flag == eof
		line-len !
		process-line
	again ;

gmi-to-html

depth throw \ ensure stack is clean
bye