Skip to content

Instantly share code, notes, and snippets.

@2bard
Created July 18, 2012 20:09

Revisions

  1. 2bard revised this gist Aug 5, 2012. 1 changed file with 0 additions and 4 deletions.
    4 changes: 0 additions & 4 deletions Readme
    Original file line number Diff line number Diff line change
    @@ -1,10 +1,6 @@
    A simple bash function to display a poem.

    <<<<<<< HEAD
    Pull the function from the .cfg into your .bash_profile by adding this line to your .bash_profile:
    =======
    Pull the function from the .cfg into your .bash_profile by adding this line to your bash profile:
    >>>>>>> bb7b971d952c438b9b917ed1b7f559d338738332

    . ~/.haiku.cfg

  2. 2bard revised this gist Aug 3, 2012. 2 changed files with 7 additions and 1 deletion.
    2 changes: 2 additions & 0 deletions .haiku.cfg
    Original file line number Diff line number Diff line change
    @@ -3,6 +3,8 @@ function unsetvars {
    unset poem
    unset poems
    unset line
    unset counter
    unset linenumber
    }


    6 changes: 5 additions & 1 deletion Readme
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,10 @@
    A simple bash function to display a poem.

    <<<<<<< HEAD
    Pull the function from the .cfg into your .bash_profile by adding this line to your .bash_profile:
    =======
    Pull the function from the .cfg into your .bash_profile by adding this line to your bash profile:
    >>>>>>> bb7b971d952c438b9b917ed1b7f559d338738332

    . ~/.haiku.cfg

    @@ -15,6 +19,6 @@ The function is called 'printhaiku', it takes one parameter: the poem file.

    In my .bash_profile I have put the following line to display a poem every time I open a new shell:

    printhaiku './haiku.txt'
    printhaiku ~/haiku.txt

    I've added an example poem file.
  3. 2bard revised this gist Aug 3, 2012. 2 changed files with 8 additions and 2 deletions.
    3 changes: 2 additions & 1 deletion Readme
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,6 @@
    A simple bash function to display a poem.

    Pull the function from the .cfg into your .bash_profile by adding this line:
    Pull the function from the .cfg into your .bash_profile by adding this line to your .bash_profile:

    . ~/.haiku.cfg

    @@ -17,3 +17,4 @@ In my .bash_profile I have put the following line to display a poem every time I

    printhaiku './haiku.txt'

    I've added an example poem file.
    7 changes: 6 additions & 1 deletion haiku.txt
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,11 @@
    "The summer grasses: / of mighty warlords' visions / all that they have left." / [Basho]
    "On my travels, stricken-- / my dreams over the dry land / go on roving." / [Basho]
    "Ancient pond / Frog leaps / Spash!" / [Basho]
    "Ancient pond / Frog leaps / Splash!" / [Basho]
    "Over the wintry / forest, winds howl in rage / with no leaves to blow." / [Soseki]
    "A sudden shower falls - / and naked I am riding / on a naked horse!" / [Issa]
    "Green frog / is your body also / freshly painted?" / [Akutagawa]
    "Spring water in the green creek is clear / Moonlight on Cold Mountain is white / Silent knowledge - the spirit is enlightened of itself / Contemplate the void: this world exceeds stillness." [Han Shan]
    "In my first thirty years of life / I roamed hundreds and thousands of miles. / Walked by rivers through deep green grass / Entered cities of boiling red dust. / Tried drugs, but couldn't make Immortal; / Read books and wrote poems on history. / Today I'm back at Cold Mountain: / I'll sleep by the creek and purify my ears." [Han Shan]
    "Once at Cold Mountain, troubles cease - / No more tangled, hung up mind. / I idly scribble poems on the rock cliff, / Taking whatever comes, like a drifting boat." [Han Shan]
    "On top of Cold Mountain the lone round moon / Lights the whole clear cloudless sky. / Honor this priceless natural treasure / Concealed in five shadows, sunk deep in the flesh." [Han Shan]

  4. Lewis B revised this gist Jul 19, 2012. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions .haiku.cfg
    Original file line number Diff line number Diff line change
    @@ -3,6 +3,8 @@ function unsetvars {
    unset poem
    unset poems
    unset line
    unset counter
    unset linenumber
    }


  5. Lewis B revised this gist Jul 19, 2012. 2 changed files with 3 additions and 3 deletions.
    4 changes: 2 additions & 2 deletions Readme
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,6 @@
    A simple bash function to display a poem.

    Pull the function from the .cfg into your .bash_profile by adding this line:
    Pull the function from the .cfg into your .bash_profile by adding this line to your bash profile:

    . ~/.haiku.cfg

    @@ -15,5 +15,5 @@ The function is called 'printhaiku', it takes one parameter: the poem file.

    In my .bash_profile I have put the following line to display a poem every time I open a new shell:

    printhaiku './haiku.txt'
    printhaiku ~/haiku.txt

    2 changes: 1 addition & 1 deletion haiku.txt
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,6 @@
    "The summer grasses: / of mighty warlords' visions / all that they have left." / [Basho]
    "On my travels, stricken-- / my dreams over the dry land / go on roving." / [Basho]
    "Ancient pond / Frog leaps / Spash!" / [Basho]
    "Ancient pond / Frog leaps / Splash!" / [Basho]
    "Over the wintry / forest, winds howl in rage / with no leaves to blow." / [Soseki]
    "A sudden shower falls - / and naked I am riding / on a naked horse!" / [Issa]
    "Green frog / is your body also / freshly painted?" / [Akutagawa]
  6. 2bard revised this gist Jul 18, 2012. 1 changed file with 6 additions and 0 deletions.
    6 changes: 6 additions & 0 deletions haiku.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,6 @@
    "The summer grasses: / of mighty warlords' visions / all that they have left." / [Basho]
    "On my travels, stricken-- / my dreams over the dry land / go on roving." / [Basho]
    "Ancient pond / Frog leaps / Spash!" / [Basho]
    "Over the wintry / forest, winds howl in rage / with no leaves to blow." / [Soseki]
    "A sudden shower falls - / and naked I am riding / on a naked horse!" / [Issa]
    "Green frog / is your body also / freshly painted?" / [Akutagawa]
  7. 2bard revised this gist Jul 18, 2012. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion .haiku.cfg
    Original file line number Diff line number Diff line change
    @@ -37,7 +37,7 @@ function echopoem {
    fi
    done

    echo $line;
    echo $line

    echo
    }
  8. 2bard revised this gist Jul 18, 2012. 1 changed file with 3 additions and 3 deletions.
    6 changes: 3 additions & 3 deletions .haiku.cfg
    Original file line number Diff line number Diff line change
    @@ -12,10 +12,10 @@ function getpoem {
    counter=`wc -l < $poems`

    #get random line number
    NUMBER=$[ ( $RANDOM % $counter ) + 1 ]
    linenumber=$[ ( $RANDOM % $counter ) + 1 ]

    #get the line
    poem=`sed -n "${NUMBER}p" < $poems`
    poem=`sed -n "${linenumber}p" < $poems`

    }

    @@ -48,4 +48,4 @@ function printhaiku {
    getpoem
    echopoem
    unsetvars
    }
    }
  9. 2bard created this gist Jul 18, 2012.
    51 changes: 51 additions & 0 deletions .haiku.cfg
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,51 @@
    function unsetvars {
    unset word
    unset poem
    unset poems
    unset line
    }


    function getpoem {

    #get number of lines in file
    counter=`wc -l < $poems`

    #get random line number
    NUMBER=$[ ( $RANDOM % $counter ) + 1 ]

    #get the line
    poem=`sed -n "${NUMBER}p" < $poems`

    }


    function echopoem {

    echo

    #go through each word
    for word in $poem; do

    #if the word isn't a newline character, add it to the output
    if [ "${word}" == "/" ];
    then
    echo $line;
    unset line;
    else
    line=$line" ${word}";
    fi
    done

    echo $line;

    echo
    }

    function printhaiku {
    unsetvars
    poems=$1
    getpoem
    echopoem
    unsetvars
    }
    19 changes: 19 additions & 0 deletions Readme
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,19 @@
    A simple bash function to display a poem.

    Pull the function from the .cfg into your .bash_profile by adding this line:

    . ~/.haiku.cfg

    Poems are to be stored in a textfile with one line per poem. A forward slash indicated a new line e.g.

    This is line 1 of the first poem / This is line 2 of the first poem
    This is line 1 of the second poem / This is line 2 of the second poem

    The bash function grabs a random poem and echoes it out line-by-line.

    The function is called 'printhaiku', it takes one parameter: the poem file.

    In my .bash_profile I have put the following line to display a poem every time I open a new shell:

    printhaiku './haiku.txt'