Browse Source

.vimrc: script-local functions & vw log utils

  - changes various BPB_Foo functions to s:FOO, which is cleaner and does
    less trampling on the global namespace

  - adds some vimwiki log / link utilities based on an SQLite db I'm
    building elsewhere

  - comments slightly clearer about how unlikely this is to work for most
    users

  - removes some cruft, including an experimental scratch wiki
Brennen Bearnes 2 months ago
parent
commit
14f4509c4a
5 changed files with 162 additions and 92 deletions
  1. 10
    7
      README.md
  2. 66
    83
      home/.vimrc
  3. 1
    2
      home/bin/fragment-vimwiki-grep-logs
  4. 85
    0
      home/bin/vimwiki-links-for
  5. 0
    0
      home/bin/vimwiki-logs-for

+ 10
- 7
README.md View File

@@ -70,18 +70,19 @@ that said code is clearly marked.
70 70
 sources
71 71
 -------
72 72
 
73
-I routinely thief ideas and bits of configuration from the following projects
74
-and people:
73
+I have thiefed ideas and bits of configuration from the following projects and
74
+people:
75 75
 
76 76
   - [Advanced Bash Scripting Guide][bash-guide], Mendel Cooper
77
-  - [Alan][alan]
77
+  - [Learn Vimscript the Hard Way][vimscript], Steve Losh
78 78
   - [ArchWiki][archwiki]
79
+  - [Alan][alan]
79 80
   - [Ben][ben]
80 81
   - [Casey][casey]
81 82
   - [Chris][chris]
82 83
   - [Dave][dave]
84
+  - [Jacky][jacky-alcine]
83 85
   - [Leah][leah]
84
-  - [Learn Vimscript the Hard Way][vimscript], Steve Losh
85 86
   - [Rob][rob]
86 87
   - [Todd][todd]
87 88
   - [Tyler][tyler]
@@ -91,9 +92,10 @@ contents
91 92
 
92 93
 ### shell stuff
93 94
 
94
-These days I use ZSH on personal systems and Bash when writing tutorials or
95
-doing tech support.  I like to keep lots and lots of history.  I think shell
96
-scripting is a nightmare for most real tasks, but I do it sometimes anyway.
95
+These days I use ZSH on personal systems and Bash when writing tutorials, doing
96
+tech support, or working on production server systems.  I like to keep lots and
97
+lots of history.  I think shell scripting is a nightmare for most real tasks,
98
+but I do it sometimes anyway.
97 99
 
98 100
   - [`.bashrc`](home/.bashrc)
99 101
   - [`.zshrc`](home/.zshrc) - nothing fancy
@@ -236,6 +238,7 @@ See instructions in [ns-control](ns-control).
236 238
 [rob]: https://github.com/robacarp/
237 239
 [todd]: https://uniontownlabs.org/
238 240
 [tyler]: https://tylercipriani.com/
241
+[jacky-alcine]: https://jacky.wtf/
239 242
 [userland]: https://p1k3.com/userland-book/
240 243
 [vimscript]: http://learnvimscriptthehardway.stevelosh.com/
241 244
 [vimwiki]: https://github.com/vimwiki/vimwiki

+ 66
- 83
home/.vimrc View File

@@ -13,11 +13,11 @@
13 13
 " hitting zR will unfold them all, while zr will unfold the one your
14 14
 " cursor is on.  this note is as much for my benefit as yours.
15 15
 "
16
-" some of this config is very specific to my preferences.  there are
17
-" keybindings for filters i use regularly, things that automatically happen
18
-" when i open certain files, and shortcuts bound to the F-keys.  you might
19
-" find good examples here, but you may not want the behavior.  don't say you
20
-" weren't warned.
16
+" an increasing percentage of this config is very specific to my preferences.
17
+" there are keybindings for filters i use regularly, things that automatically
18
+" happen when i open certain files, and shortcuts bound to the F-keys.  quite
19
+" a lot of the behavior here also assumes it'll have scripts found in ~/bin
20
+" - see home/bin in this repo - and may rely on tools i haven't yet published.
21 21
 "
22 22
 " items particularly likely to be personal preference are marked with the
23 23
 " string CUSTOMIZE and a note.
@@ -73,7 +73,7 @@ let mapleader = ","
73 73
 
74 74
   " fancy start screen with recent files & bookmarks
75 75
   " CUSTOMIZE: you'll probably want different bookmarks
76
-  " Plugin 'mhinz/vim-startify'
76
+  Plugin 'mhinz/vim-startify'
77 77
   " let g:startify_bookmarks = [ {'v': '~/.vimrc'}, '~/.zshrc', '~/notes/', '~/p1k3' ]
78 78
 
79 79
   " Vim Outliner of Markups - see :help voom - no idea yet if this is any good
@@ -143,7 +143,6 @@ let mapleader = ","
143 143
   Plugin 'DrawIt'
144 144
 
145 145
   " most recently used files - my fork allows for a top-level menu
146
-  let g:MRU_Exclude_Files = '^/home/brennen/scratchnotes/.*'  " For Unix
147 146
   let g:MRU_Menu_Path = '&Recent\ Files'
148 147
   let g:MRU_Max_Menu_Entries = 30
149 148
   let g:MRU_Max_Submenu_Entries = 30
@@ -237,15 +236,7 @@ let mapleader = ","
237 236
     let wiki.auto_diary_index = 1
238 237
     let wiki.automatic_nested_syntaxes = 1
239 238
 
240
-    " disposable scratch notes
241
-    let scratchwiki = {}
242
-    let scratchwiki.path = '~/scratchnotes'
243
-    let scratchwiki.path_html = '~/scratchnotes/html/'
244
-    let scratchwiki.auto_tags = 1
245
-    let scratchwiki.auto_diary_index = 1
246
-    let scratchwiki.automatic_nested_syntaxes = 1
247
-
248
-    " disposable scratch notes
239
+    " a markdown wiki for testing purposes
249 240
     let markdownwiki = {}
250 241
     let markdownwiki.path = '~/notes/markdownwiki'
251 242
     let markdownwiki.path_html = '~/notes/markdownwiki/html/'
@@ -282,7 +273,7 @@ let mapleader = ","
282 273
     set complete=.,w,b,u,t,i,k
283 274
 
284 275
     " there can be many of these
285
-    let g:vimwiki_list = [wiki, scratchwiki, markdownwiki]
276
+    let g:vimwiki_list = [wiki, markdownwiki]
286 277
 
287 278
     " don't make temporary wikis based on file extensions in the list
288 279
     let g:vimwiki_global_ext = 0
@@ -348,14 +339,9 @@ let mapleader = ","
348 339
     " run new diary entry template:
349 340
     au BufNewFile *vimwiki/log/*.wiki :0r !fragment-vimwiki-log '%'
350 341
 
351
-    " regenerate task lists and index on file load:
352
-    au BufReadPost *vimwiki/tasks-auto.wiki call BPB_RunFilter("filter-exec-raw")
353
-    au BufReadPost *vimwiki/index.wiki call BPB_RunFilter("filter-exec-raw")
354
-    au BufReadPost *vimwiki/log/index.wiki call BPB_RunFilter("filter-exec-raw")
355
-
356 342
     " set up linewrapping so that long lines more or less work
357
-    au BufRead,BufNewFile *.wiki call BPB_LonglineMode()
358
-    au BufReadPost *.wiki call BPB_BufReadPostOverrides()
343
+    au BufRead,BufNewFile *.wiki call <SID>LonglineMode()
344
+    au BufReadPost *.wiki call <SID>WikiBufReadPostOverrides()
359 345
 
360 346
   " }}}
361 347
 
@@ -528,14 +514,13 @@ let mapleader = ","
528 514
   "
529 515
   " this used to fail for files named `index`, because of a fugitive bug:
530 516
   " https://github.com/tpope/vim-fugitive/issues/834
531
-  au BufReadPost,BufNewFile * call BPB_FiletypeOverrides()
532
-  " au BufReadPost * call BPB_BufReadPostOverrides()
517
+  au BufReadPost,BufNewFile * call <SID>FiletypeOverrides()
533 518
 
534
-  au BufNewFile * call BPB_NewFileOverrides()
519
+  au BufNewFile * call <SID>NewFileOverrides()
535 520
 
536 521
   " TODO: make a colorscheme logger here - it'd be nice to know all the
537 522
   " schemes i ever use for later reference:
538
-  " au ColorScheme * call BPB_ColorSchemeOverrides()
523
+  " au ColorScheme * call <SID>ColorSchemeOverrides()
539 524
 
540 525
 " }}}
541 526
 
@@ -547,7 +532,7 @@ let mapleader = ","
547 532
   " 'namespace' too much, with the exception of replacing K with something
548 533
   " useful.
549 534
 
550
-  " a handful of functions are called here, all with a prefix of BPB_ -
535
+  " a handful of functions are called here, all with a prefix of <SID> -
551 536
   " they can be found in the "functions" section below
552 537
 
553 538
   " many things here have menu entries under 'Cheatsheet', as a cheatsheet for
@@ -571,8 +556,8 @@ let mapleader = ","
571 556
 
572 557
   " this version cycles through a couple versions of relative and absolute
573 558
   " line numbers:
574
-  " map <F4> :call BPB_CycleLineNumbers()<CR>
575
-  " imap <F4> <Esc>:call BPB_CycleLineNumbers()<CR>
559
+  " map <F4> :call <SID>CycleLineNumbers()<CR>
560
+  " imap <F4> <Esc>:call <SID>CycleLineNumbers()<CR>
576 561
 
577 562
   amenu Cheatsheet.Toggle\ Line\ Numbers<Tab>F4 <F4>
578 563
 
@@ -591,19 +576,22 @@ let mapleader = ","
591 576
   " see http://learnvimscriptthehardway.stevelosh.com/chapters/07.html for
592 577
   " rationale - the idea is to make changing vim configuration trivial
593 578
   if has('nvim')
594
-    map <F7> :call BPB_TabDrop("~/.vimrc")<CR>
579
+    map <F7> :call <SID>TabDrop("~/.vimrc")<CR>
595 580
   else
596
-    map <F7> :call BPB_TabDrop($MYVIMRC)<CR>
581
+    map <F7> :call <SID>TabDrop($MYVIMRC)<CR>
597 582
   endif
598 583
 
599 584
   imap <F7> <Esc><F7>
600 585
   amenu Cheatsheet.Open\ \.vimrc<Tab>F7 <F7>
601 586
 
602
-  " F8 inserts an ISO-8601 datestamp (eight rhymes with date)
587
+  " F8 inserts an ISO-8601 datestamp (mnemonic: eight rhymes with date)
603 588
   " (used to open the options window; use :options for that)
604 589
   map <F8> :r !date -I<CR>kJ
590
+
605 591
   " ,F8 inserts a date with seconds precision
606 592
   map <Leader><F8> :r !date -Is<CR>kJ
593
+
594
+  " ,td / ,tD do the same (mnemonic: toDay)
607 595
   map <Leader>td :r !date -I<CR>kJ
608 596
   map <Leader>tD :r !date -Is<CR>kJ
609 597
 
@@ -611,7 +599,7 @@ let mapleader = ","
611 599
   amenu Cheatsheet.Insert\ Datestamp<Tab>F8 <F8>
612 600
 
613 601
   " F9 toggles search highlighting and some other noise
614
-  map <F9> :call BPB_Crosshairs()<CR>
602
+  map <F9> :call <SID>Crosshairs()<CR>
615 603
   imap <F9> <Esc><F9>
616 604
   amenu Cheatsheet.Crosshairs<Tab>F9 <F9>
617 605
 
@@ -637,11 +625,11 @@ let mapleader = ","
637 625
   amenu Cheatsheet.Split\ Line<Tab>K K
638 626
 
639 627
   " an FZF fragment menu
640
-  nmap <Leader>F :call BPB_FragmentMenu()<CR>
628
+  nmap <Leader>F :call <SID>FragmentMenu()<CR>
641 629
   amenu Cheatsheet.Fragment\ Menu<Tab>,F <Leader>F
642 630
 
643 631
   " CUSTOMIZE: randomize certain text decorations - silly
644
-  nmap <Leader>D :call BPB_RunFilter("filter-decorate")<CR>
632
+  nmap <Leader>D :call <SID>RunFilter("filter-decorate")<CR>
645 633
   amenu Cheatsheet.Randomize\ Decorations<Tab>,D <Leader>D
646 634
   nmap <Leader>d i<p class="centerpiece"> <Esc>:r !fragment-bullet<CR>kJA </p><Esc>
647 635
   amenu Cheatsheet.Insert\ Decoration<Tab>,d <Leader>d
@@ -653,12 +641,12 @@ let mapleader = ","
653 641
 
654 642
   " i didn't wind up using this much, and it potentially messes
655 643
   " with vimwiki mappings:
656
-  " nmap <Leader>w :call BPB_CommandOutputInNewWindow("dict <cword>"))<CR>
644
+  " nmap <Leader>w :call <SID>CommandOutputInNewWindow("dict <cword>"))<CR>
657 645
 
658 646
   " pull up the last hundred git commits in a scratch buffer
659 647
   " nmap <Leader>l :vnew<CR>:set buftype=nofile<CR>:set bufhidden=hide<CR>:setlocal noswapfile<CR>:r !git log -100<CR>:set ft=git<CR>gg<C-w>r<C-w>l
660 648
   nmap <Leader>gl :Glog<CR>:copen<CR>
661
-  amenu Cheatsheet.Git\ Log<Tab>,l <Leader>l
649
+  amenu Cheatsheet.Git\ Log<Tab>,gl <Leader>gl
662 650
 
663 651
   nmap <leader>m :make<CR>
664 652
   amenu Cheatsheet.Make<Tab>,m <Leader>m
@@ -689,7 +677,7 @@ let mapleader = ","
689 677
 
690 678
   " CUSTOMIZE: these are simple filter scripts to preprocess some
691 679
   " shell commands in HTML or Markdown files - see scripts for details
692
-  nmap <Leader>r :call BPB_RunFilter("filter-exec-raw")<CR>:call BPB_RunFilter("filter-exec")<CR>:call BPB_RunFilter("filter-exec-stdin")<CR>
680
+  nmap <Leader>r :call <SID>RunFilter("filter-exec-raw")<CR>:call <SID>RunFilter("filter-exec")<CR>:call <SID>RunFilter("filter-exec-stdin")<CR>
693 681
   amenu Cheatsheet.Run\ Filters<Tab>,r <Leader>r
694 682
 
695 683
   " delete trailing whitespace, file-wide
@@ -710,8 +698,8 @@ let mapleader = ","
710 698
   amenu Cheatsheet.New\ Tab<Tab>,tn <Leader>tn
711 699
 
712 700
   " run timeslice script for current file:
713
-  nmap <Leader>ts :call BPB_TimesliceForFile()<CR>
714
-  amenu Cheatsheet.Timeslice<Tab>,ts :call BPB_TimesliceForFile()<CR>
701
+  nmap <Leader>ts :call TimesliceForFile()<CR>
702
+  amenu Cheatsheet.Timeslice<Tab>,ts :call TimesliceForFile()<CR>
715 703
 
716 704
   " trigger unite.vim
717 705
   map <Leader>u :Unite<CR>
@@ -729,12 +717,14 @@ let mapleader = ","
729 717
   map <Leader>w/ :VimwikiSearch
730 718
 
731 719
   " create a new 'log' entry in vimwiki
732
-  " map <Leader>wl :VimwikiIndex<CR>:VimwikiGoto `date '+/home/brennen/notes/vimwiki/log/\%Y-\%m-\%d-\%H\%M-\%S.wiki'`<CR>
733
-  map <Leader>wl :e `date '+/home/brennen/notes/vimwiki/log/\%Y-\%m-\%d-\%H\%M-\%S.wiki'`<CR>
720
+  map <Leader>wl :e `date '+~/notes/vimwiki/log/\%Y-\%m-\%d-\%H\%M-\%S.wiki'`<CR>
734 721
 
735 722
   " view log for current wiki page
736 723
   " TODO: consider extending this to all files in some way...
737
-  map <Leader>l :call BPB_LogForWikiPage()<CR>
724
+  map <Leader>l :call <SID>LogForWikiPage()<CR>
725
+
726
+  " view backlinks for current wiki page
727
+  map <Leader>L :call <SID>VimwikiLinksForFile()<CR>
738 728
 
739 729
   " check php syntax - replaced by using Syntastic
740 730
   " noremap <Leader>c :echom system('php -l ' . bufname('%'))<CR>
@@ -746,14 +736,14 @@ let mapleader = ","
746 736
   " run the file through a custom filter, leaving the cursor at its original
747 737
   " location in the file (or close) - there might be a better way to do this,
748 738
   " but i don't know what it is
749
-  function! BPB_RunFilter(filter)
739
+  function! s:RunFilter(filter)
750 740
     let l:currentline = line('.')
751 741
     exe ":%!" . a:filter
752 742
     exe ":" . l:currentline
753 743
   endfunction
754 744
 
755 745
   " do some normal-mode commands and return the cursor to its previous location
756
-  function! BPB_ExecNormalAndReturnCursor(commands)
746
+  function! s:ExecNormalAndReturnCursor(commands)
757 747
     let l:currentline = line('.')
758 748
     " see http://learnvimscriptthehardway.stevelosh.com/chapters/30.html
759 749
     exe "normal! " . a:commands
@@ -761,7 +751,7 @@ let mapleader = ","
761 751
   endfunction
762 752
 
763 753
   " set custom filetypes for some things - invoked by an autocommand above
764
-  function! BPB_FiletypeOverrides()
754
+  function! s:FiletypeOverrides()
765 755
     " make sure NERDTree windows don't get messed up
766 756
     if bufname("%") =~ "NERD_tree"
767 757
       return
@@ -781,29 +771,16 @@ let mapleader = ","
781 771
     endif
782 772
   endfunction
783 773
 
784
-  " take some custom actions after reading a file:
785
-  function! BPB_BufReadPostOverrides()
786
-    " make sure NERDTree windows don't get messed up
787
-    if bufname("%") =~ "NERD_tree"
788
-      return
774
+  " take some custom actions after reading a wiki page:
775
+  function! s:WikiBufReadPostOverrides()
776
+    " regenerate wiki pages with `%% exec-raw auto` on page load
777
+    if search("%% exec-raw auto", "nw")
778
+      call <SID>RunFilter("filter-exec-raw")
789 779
     endif
790
-
791
-    " XXX: this doesn't quite work right now - maybe because VimwikiTOC isn't
792
-    " defined yet at this point?  filetype isn't in place yet?  need to figure that out...
793
-    "
794
-    " regenerate table of contents in vimwiki pages if there's already one in
795
-    " the buffer - probably this should be grouped with vimwiki config, or
796
-    " submitted as a patch to vimwiki itself with some optional configuration
797
-    " if expand('%:p') =~# "\\vvimwiki\/.*\.wiki$"
798
-    "   " echom 'vimwiki match - running contents update'
799
-    "   if search("= Contents =", "nw")
800
-    "     :VimwikiTOC
801
-    "   endif
802
-    " endif
803 780
   endfunction
804 781
 
805 782
   " if editing a new p1k3 entry, auto-populate with a datestamp
806
-  function! BPB_NewFileOverrides()
783
+  function! s:NewFileOverrides()
807 784
     if expand('%:p') =~# "\\vp1k3\/archives.*\/([0-9]|[a-z])+$"
808 785
       silent 0r !fragment-entry
809 786
     endif
@@ -812,7 +789,7 @@ let mapleader = ","
812 789
   " spit out a date for today, using ~/bin/fragment-today, on the current line
813 790
   " TODO: ideally this would context sensitive:  if called inside a vimwiki
814 791
   " diary file or a p1k3 blog entry, it would use that date instead.
815
-  function! BPB_Datestamp()
792
+  function! s:Datestamp()
816 793
     " . is current line, -1 is 1 line above that, r would otherwise read
817 794
     " the output onto the line below the cursor
818 795
     .-1r !fragment-today
@@ -820,7 +797,7 @@ let mapleader = ","
820 797
 
821 798
   " select a fragment script using fzf and include its output in the
822 799
   " current buffer
823
-  function! BPB_FragmentMenu()
800
+  function! s:FragmentMenu()
824 801
     call fzf#run({
825 802
       \ 'options': '--reverse',
826 803
       \ 'sink': '.-1r !',
@@ -829,18 +806,18 @@ let mapleader = ","
829 806
   endfunction
830 807
 
831 808
   " spit out a current timestamp
832
-  function! BPB_Timestamp()
809
+  function! s:Timestamp()
833 810
     .-1r !rightnow
834 811
   endfunction
835 812
 
836
-  function! BPB_ColorSchemeOverrides()
813
+  function! s:ColorSchemeOverrides()
837 814
   endfunction
838 815
 
839 816
   " make things more amenable to editing long soft-wrapped lines
840 817
   " mostly an attempt to make vimwiki a bit more ergonomic, this
841 818
   " version adapted from:
842 819
   " http://www.baryudin.com/blog/vim-line-wrapping-and-word-boundary.html
843
-  function! BPB_LonglineMode()
820
+  function! s:LonglineMode()
844 821
     setlocal wrap linebreak
845 822
     set virtualedit=
846 823
     setlocal display+=lastline
@@ -858,7 +835,7 @@ let mapleader = ","
858 835
 
859 836
   " add some display sugar that helps highlight cursor, searches, and
860 837
   " textwidth.  good for fiddling with alignment, reflowing text, etc.
861
-  function! BPB_Crosshairs()
838
+  function! s:Crosshairs()
862 839
     set invhlsearch
863 840
     set invcursorcolumn
864 841
     set invcursorline
@@ -873,7 +850,7 @@ let mapleader = ","
873 850
   endfunction
874 851
 
875 852
   " cycle between no, absolute, and relative line numbers
876
-  function! BPB_CycleLineNumbers()
853
+  function! s:CycleLineNumbers()
877 854
     if (&number)
878 855
       set nonumber
879 856
       return
@@ -888,7 +865,7 @@ let mapleader = ","
888 865
 
889 866
   " this is pretty much horked from:
890 867
   " http://vim.wikia.com/wiki/Display_output_of_shell_commands_in_new_window
891
-  function! BPB_CommandOutputInNewWindow(cmdline)
868
+  function! s:CommandOutputInNewWindow(cmdline)
892 869
     echo a:cmdline
893 870
     let expanded_cmdline = a:cmdline
894 871
     for part in split(a:cmdline, ' ')
@@ -919,25 +896,31 @@ let mapleader = ","
919 896
   " tab drop (edit in existing or new tab) a file's real path, in case it is a
920 897
   " symlink - useful for, frex, symlinked .vimrc.  does wildcard expansion on
921 898
   " the path.  as usual, there are probably better ways to do all of this.
922
-  function! BPB_TabDrop(path)
899
+  function! s:TabDrop(path)
923 900
     let realpath = system('readlink -fn ' . shellescape(expand(a:path)))
924 901
     echom realpath
925 902
     execute 'tab drop ' . realpath
926 903
   endfunction
927 904
 
928 905
   " try to run timeslice for current path
929
-  function! BPB_TimesliceForFile()
906
+  function! g:TimesliceForFile()
907
+    let realpath = system('readlink -fn ' . shellescape(expand('%')))
908
+    call <SID>CommandOutputInNewWindow('timeslice -f ' . realpath)
909
+  endfunction
910
+
911
+  " try to run vimwiki-links-for for current path
912
+  function! s:VimwikiLinksForFile()
930 913
     let realpath = system('readlink -fn ' . shellescape(expand('%')))
931
-    call BPB_CommandOutputInNewWindow('timeslice -f ' . realpath)
914
+    call <SID>CommandOutputInNewWindow('vimwiki-links-for --file ' . realpath)
932 915
   endfunction
933 916
 
934 917
   " XXX: Experimental - catenate log entries for current wiki page
935
-  function! BPB_LogForWikiPage()
918
+  function! s:LogForWikiPage()
936 919
     let realpath = system('readlink -fn ' . shellescape(expand('%')))
937 920
     botright new
938 921
     edit ~/notes/vimwiki/_logscratch.wiki
939 922
     1,$d " delete everything in file
940
-    execute '$read !' . 'logs-for ' . realpath
923
+    execute '$read !' . 'vimwiki-logs-for ' . realpath
941 924
     0delete " delete blank first line - get rid of this if you need debug msgs
942 925
     1
943 926
   endfunction
@@ -945,13 +928,13 @@ let mapleader = ","
945 928
   " get a list of key bindings, along with where they were defined, and
946 929
   " open it in a tab.  this variant of redir and map seen at:
947 930
   " https://stackoverflow.com/questions/7642746/is-there-any-way-to-view-the-currently-mapped-keys-in-vim#7642762
948
-  function! BPB_ListBindings()
931
+  function! g:ListBindings()
949 932
     redir! > ~/vim_keys.txt
950 933
     silent verbose map
951 934
     redir END
952
-    call BPB_TabDrop("~/vim_keys.txt")
935
+    call <SID>TabDrop("~/vim_keys.txt")
953 936
   endfunction
954
-  amenu Cheatsheet.List\ Keys<Tab>:call\ BPB_ListBindings() :call BPB_ListBindings()<CR>
937
+  amenu Cheatsheet.List\ Keys<Tab>:call\ ListBindings() :call ListBindings()<CR>
955 938
 
956 939
 " }}}
957 940
 

+ 1
- 2
home/bin/fragment-vimwiki-grep-logs View File

@@ -12,8 +12,7 @@ else
12 12
   datestamp="$(date -I)"
13 13
 fi
14 14
 
15
-
16 15
 echo '== log =='
17 16
 echo
18
-echo "{{{exec-raw grep '%title' ./vimwiki/log/${datestamp}*.wiki"
17
+echo "{{{exec-raw find ./vimwiki/log -name '${datestamp}*.wiki' | sort | xargs grep --with-filename '%title'"
19 18
 echo '}}}'

+ 85
- 0
home/bin/vimwiki-links-for View File

@@ -0,0 +1,85 @@
1
+#!/usr/bin/env perl
2
+
3
+=pod
4
+
5
+=head1 NAME
6
+
7
+vimwiki-links-for - show links for a given target in a vimwiki
8
+
9
+=head1 SYNOPSIS
10
+
11
+    # Show links for foo
12
+    vimwiki-links-for --target foo
13
+
14
+    # Show links for foo.wiki:
15
+    vimwiki-links-for --file ./foo.wiki
16
+
17
+=head1 AUTHOR
18
+
19
+Brennen Bearnes
20
+
21
+=cut
22
+
23
+use warnings;
24
+use strict;
25
+use 5.10.0;
26
+
27
+use Cwd;
28
+use Data::Dumper;
29
+use DBI;
30
+use File::Basename;
31
+use File::Spec;
32
+use Getopt::Long;
33
+use Pod::Usage;
34
+use SQL::Abstract;
35
+use Sys::Hostname;
36
+
37
+use App::CommandLog;
38
+
39
+# Handle options, including help generated from the POD above.
40
+my $debug = 0;
41
+my $target;
42
+my $file;
43
+GetOptions(
44
+  'debug'    => \$debug,
45
+  'target=s' => \$target,
46
+  'file=s'   => \$file,
47
+  'help'     => sub { pod2usage(0) },
48
+) or pod2usage(2);
49
+
50
+if (defined $file) {
51
+  my ($name, $path, $suffix) = fileparse($file, '.wiki');
52
+  $target = $name;
53
+}
54
+
55
+unless (defined $target) {
56
+  die "Must give a --target or a --file";
57
+}
58
+
59
+my %where = ();
60
+$where{target} = $target;
61
+
62
+my $dbfile = $ENV{HOME} . "/notes/vimwiki.db";
63
+my $dbh = DBI->connect("dbi:SQLite:dbname=$dbfile", "", "");
64
+
65
+my $sql = SQL::Abstract->new;
66
+my ($query, @bind) = $sql->select(
67
+  'links',
68
+  '*',
69
+  \%where,
70
+  {-desc => 'target'}
71
+);
72
+
73
+if ($debug) {
74
+  say STDERR $query;
75
+  say STDERR Dumper(%where);
76
+}
77
+
78
+my $sth = $dbh->prepare($query);
79
+$sth->execute(@bind);
80
+
81
+while (my $data = $sth->fetchrow_hashref()) {
82
+  say $data->{page};
83
+}
84
+
85
+$sth->execute();

home/bin/logs-for → home/bin/vimwiki-logs-for View File


Loading…
Cancel
Save