|
| 1 | +#compdef notes |
| 2 | +# ------------------------------------------------------------------------------ |
| 3 | +# Copyright (c) 2016 Github zsh-users - http://github.com/zsh-users |
| 4 | +# All rights reserved. |
| 5 | +# |
| 6 | +# Redistribution and use in source and binary forms, with or without |
| 7 | +# modification, are permitted provided that the following conditions are met: |
| 8 | +# * Redistributions of source code must retain the above copyright |
| 9 | +# notice, this list of conditions and the following disclaimer. |
| 10 | +# * Redistributions in binary form must reproduce the above copyright |
| 11 | +# notice, this list of conditions and the following disclaimer in the |
| 12 | +# documentation and/or other materials provided with the distribution. |
| 13 | +# * Neither the name of the zsh-users nor the |
| 14 | +# names of its contributors may be used to endorse or promote products |
| 15 | +# derived from this software without specific prior written permission. |
| 16 | +# |
| 17 | +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND |
| 18 | +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
| 19 | +# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
| 20 | +# DISCLAIMED. IN NO EVENT SHALL ZSH-USERS BE LIABLE FOR ANY |
| 21 | +# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
| 22 | +# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
| 23 | +# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND |
| 24 | +# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 25 | +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
| 26 | +# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 27 | +# ------------------------------------------------------------------------------ |
| 28 | +# Description |
| 29 | +# ----------- |
| 30 | +# |
| 31 | +# Simple delightful note taking, with more unix and less lock-in. (https://github.com/pimterry/notes) |
| 32 | +# |
| 33 | +# ------------------------------------------------------------------------------ |
| 34 | +# Authors |
| 35 | +# ------- |
| 36 | +# |
| 37 | +# * Tim Perry (https://github.com/pimterry) |
| 38 | +# * Stefen Ramirez (https://github.com/RODNOTGOD) |
| 39 | +# |
| 40 | +# ------------------------------------------------------------------------------ |
| 41 | + |
| 42 | +__notes_cmd () |
| 43 | +{ |
| 44 | + local -a list |
| 45 | + list=( |
| 46 | + new:'Create new file' |
| 47 | + ls:'<pattern> List notes by path' |
| 48 | + find:'[pattern] Search notes by filename and path' |
| 49 | + grep:'<pattern> Search notes by content' |
| 50 | + open:'<name> Open a notes for editing by full name' |
| 51 | + rm:'[-r | --recursive] <name> Remove note, or folder if -r or --recursive is given]' |
| 52 | + --help:'Show usage' |
| 53 | + ) |
| 54 | + _describe -t sub-commands 'sub commands' list && _ret=0 |
| 55 | +} |
| 56 | + |
| 57 | +_notes () |
| 58 | +{ |
| 59 | + local configured_dir=${NOTES_DIRECTORY%/} |
| 60 | + local note_dir="${configured_dir:-$HOME/notes}" |
| 61 | + |
| 62 | + if (($CURRENT == 2)); then |
| 63 | + _alternative 'sub-commands:files:__notes_cmd' && _ret=0 |
| 64 | + elif (($CURRENT == 3)); then |
| 65 | + case $words[2] in |
| 66 | + open|rm|new) |
| 67 | + _path_files -W "${note_dir}" && _ret=0;; |
| 68 | + ls) |
| 69 | + _path_files -W "${note_dir}" -/ && _ret=0;; |
| 70 | + esac |
| 71 | + fi |
| 72 | +} |
| 73 | + |
| 74 | +# Local Variables: |
| 75 | +# mode: Shell-Script |
| 76 | +# sh-indentation: 2 |
| 77 | +# indent-tabs-mode: nil |
| 78 | +# sh-basic-offset: 2 |
| 79 | +# End: |
| 80 | +# vim: ft=zsh sw=2 ts=2 et |
0 commit comments