Re: [OT]Bram fortune file. Know your smileys.
- Kazuo Teramoto wrote:
> Hi,Here's a variation on Bram's "fortunes.vim" script for use when not using Vim
> I love the Bram fortune file (I read it all, is fun) but now looks it
> be updated (with From "know your smileys" and jokes about proofs...)
> but it is not updated in Bram site, anyone know from are Bram take the
> 'know your smileys'?
> PS. I love the vim list, really, I read it for fun, I don't post so
> much but I think we have one of the best ml or better one of the best
> user community.
to write mail: I wrote this into my vimrc and checked that it works:
" move first fortune (with initial sig delimiter)
" to the bottom and the clipboard
au BufRead fortunes.txt
\ map <buffer> <F5>
\ :1;/^-- $/-1d +
\ <Bar>$put +
This is not perfect: you may want to create a more complex mapping to insert
your fixed sig after the "-- " line after moving the fortune. The above requires:
1. modification of the fortunes.txt file (as follows) to use "proper" sig
delimiters as separators:
This adds 529 (decimal) bytes to the file, which I think is acceptable.
2. a Vim version with access to the clipboard (i.e., any version of gvim, or a
console Vim compiled with clipboard support and running in a terminal with
access to the clipboard). This should also be a Vim version 6.1 or later, and
preferably 6.1.092 or later, because of the ":map <buffer>" command. ;-)
To use it, open fortunes.txt in Vim, hit F5, then go to your mailer, place the
cursor on an empty line after last line, and paste. You may then add the fixed
part of your sig below the delimiter. (Of course, replace <F5> by another key
to map it to something else.)
Note: I just found that on Linux systems such as mine, the "fortune" shell
command will deliver random aphorisms. Use "fortune -f" to list fortune files,
"fortune" for a random non-offensive fortune, "man fortune" for details.
However I don't know how to add a database (a pair of files, "something" in
text format and "something.dat" in binary format) to the list. I think I'll
write a function to get fortunes from both Bram's and the Linux lists.
... Done (I think I put the necessary safeguards into it to make it portable).
Two status variables are remembered across Vim runs if the viminfo is enabled.
Two more varaiables are initialized at first call. With the settings below,
Bram's fortunes will happen 20% of the time (on Unix when both ~/fortunes.txt
and the fortune program are present). Change g:FortuneCycle to alter that.
Each call to the function Fortune() returns a new fortune both as the return
value and in the clipboard, except when neither source of aphorisms is
installed, in which case it returns the empty string.
-- Replace ":echo" by ":call" in the mapping to avoid displaying the fortune
if has("viminfo") && (&viminfo != "")
" append at left end because the viminfo name (if present)
" must be last
" In order to remember them in the viminfo,
" the first two variables defined below
" must have names starting with an uppercase letter
" and containing no lowercase letters.
let g:FORTUNE = 0
let g:FORTUNECYCLE = 5
let s:sysFortunes =
\ (system("which fortune") != "") && (!v:shell_error)
let s:bramFortunes =
if s:sysFortunes && (g:FORTUNE || (!s:bramFortunes))
let @+ = "-- \n" . system("fortune -a")
silent 1;/^-- $/-1d +
let @+ = ""
let g:FORTUNE = g:FORTUNE + 1
if g:FORTUNE >= g:FORTUNECYCLE
let g:FORTUNE = 0
map <F5> :echo Fortune()<CR>
Too clever is dumb.
-- Ogden Nash