[download]

local/bin/wikimenu

   1 #!/bin/bash
   2 
   3 cd ~/Заметки || exit
   4 
   5 icon=$(icon document)
   6 wiki(){ # {{{
   7     declare -A pages tags heads
   8 
   9     while       read a b; do pages[$b]=$a;   done < <(find -name $1\*.wiki -printf '%T+ %p\n')
  10     while IFS=: read a b; do tags[$a]+="$b"; done < <(grep -io ':[0-9a-zа-я:_-]\+:' "${!pages[@]}")
  11     while IFS=: read a b; do heads[$a]="$b"; done < <(grep -io '^= [^=]*' "${!pages[@]}")
  12 
  13     for page in "${!pages[@]}"; do
  14         time=${pages[$page]}
  15         tags=${tags[$page]}
  16         tags=${tags//::/:}
  17         head=${heads[$page]#= }
  18 
  19         page=${page#./}
  20         page=${page%.wiki}
  21 
  22         printf '%s\t%s\t%s\t%s\n' "$time" "$page" "${head:- }" "${tags:-:безтемы:}"
  23     done | sort -r | cut -f 2- | sed "s/^/$icon /" | column -ts $'\t'
  24 } # }}}
  25 
  26 [[ $1 == -b ]] || wiki     | menu -i wiki  -l 20 | awk -F '   *' '{ print $2 }' | xargs -rI % gvim %.wiki
  27 [[ $1 == -b ]] && wiki 202 | menu -i bloge -l 20 | cut -d ' ' -f 3              | xargs -rI % gvim %.wiki