├── README.md ├── cheatsheet.template.txt ├── LICENSE └── cheatsheet.plugin.zsh /README.md: -------------------------------------------------------------------------------- 1 | An oh-my-zsh plug-in to easily view, create, and edit cheatsheets. 2 | -------------------------------------------------------------------------------- /cheatsheet.template.txt: -------------------------------------------------------------------------------- 1 | # Some guidance, but not absolutely necessary: 2 | # 3 | # * Keep columns 8 tabs apart. 4 | # * Provide a space after each section. 5 | # * Underlines are the width of the word. 6 | # * Try to keep descriptions within a single line. 7 | # 8 | # The cheatsheet will be displayed exactly as you see it here - as a flat text file. 9 | # Comments are ignored, but only if they occupy the entire line on their own - 10 | # trailing comments are not ignored. 11 | # 12 | SECTION 13 | ------- 14 | : 15 | : 16 | 17 | E.G. NAVIGATION 18 | --------------- 19 | : 20 | : 21 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | This is free and unencumbered software released into the public domain. 2 | 3 | Anyone is free to copy, modify, publish, use, compile, sell, or 4 | distribute this software, either in source code form or as a compiled 5 | binary, for any purpose, commercial or non-commercial, and by any 6 | means. 7 | 8 | In jurisdictions that recognize copyright laws, the author or authors 9 | of this software dedicate any and all copyright interest in the 10 | software to the public domain. We make this dedication for the benefit 11 | of the public at large and to the detriment of our heirs and 12 | successors. We intend this dedication to be an overt act of 13 | relinquishment in perpetuity of all present and future rights to this 14 | software under copyright law. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 18 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 19 | IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR 20 | OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 21 | ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 22 | OTHER DEALINGS IN THE SOFTWARE. 23 | 24 | For more information, please refer to 25 | -------------------------------------------------------------------------------- /cheatsheet.plugin.zsh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/zsh 2 | 3 | __CS_LOCAL_DIR="$(dirname $0)/"; 4 | __CS_TEMPLATE="${__CS_LOCAL_DIR}/cheatsheet.template.txt"; 5 | __CS_SHEETS="${HOME}/.config/cs-zsh/sheets"; 6 | __CS_EDITOR=$EDITOR; 7 | 8 | if [[ ! -e $EDITOR ]]; then 9 | __CS_EDITOR="vim"; 10 | fi 11 | 12 | if [[ ! -e "$__CS_SHEETS" ]]; then 13 | # make a storage location for sheets 14 | mkdir -p ${__CS_SHEETS}; 15 | fi 16 | 17 | function __cs_help() { 18 | echo -e "Usage: cs [OPTION] [CHEATSHEET NAME]"; 19 | 20 | echo -e "\nYou can view an existing cheatsheet by providing the sheet" 21 | echo -e " name as the only arg: 'cs my-cheatsheet'" 22 | 23 | echo -e "\nOptions:" 24 | 25 | echo -e " help, -h, --help \t\t show this help menu" 26 | 27 | echo -e " add, -a, --add, \t\t create a new cheatsheet" 28 | echo -e " create, -c, --create" 29 | 30 | echo -e " edit, -e, --edit \t\t edit an existing cheatsheet" 31 | echo -e " list, -l, --list \t\t list all existing cheatsheets" 32 | echo -e " show, ls" 33 | echo -e " remove, -r, --remove \t remove an existing cheatsheet" 34 | echo -e " delete, -d, --delete" 35 | echo -e " del, rm, --del" 36 | 37 | echo -e "\nExamples:" 38 | echo -e " cs add my-cheatsheet" 39 | echo -e " cs list" 40 | echo -e " cs my-cheatsheet" 41 | echo -e " cs edit my-cheatsheet" 42 | echo -e " cs remove my-cheatsheet" 43 | echo -e "" 44 | } 45 | 46 | function __cs_display_cheatsheet() { 47 | # $1 is sheet name 48 | local sheet="${__CS_SHEETS}/${1}" 49 | 50 | if [ ! -f $sheet ]; then 51 | echo "cs: cheatsheet does not exist -- '${1}'"; 52 | echo "Try 'cs list' to get a list of existing cheatsheets."; 53 | return 1; 54 | fi 55 | 56 | cat $sheet | grep -vE '^#'; # ignore comments 57 | } 58 | 59 | function __cs_add_cheatsheet() { 60 | # $1 is sheet name 61 | local sheet="${__CS_SHEETS}/${1}" 62 | 63 | [ -z $1 ] && echo "cs: you must provide a cheatsheet name" && return 1; 64 | [ -f $sheet ] && echo "cs: cheatsheet already exists -- '${1}'" && return 1; 65 | 66 | cp $__CS_TEMPLATE $sheet; 67 | $__CS_EDITOR $sheet; 68 | } 69 | 70 | function __cs_remove_cheatsheet() { 71 | # $1 is sheet name 72 | [ -z $1 ] && echo "cs: you must provide a cheatsheet name" && return 1; 73 | 74 | local sheet="${__CS_SHEETS}/${1}"; 75 | 76 | if [ ! -f $sheet ]; then 77 | echo "cs: cheatsheet does not exist -- '${1}'"; 78 | echo "Try 'cs list' to get a list of existing cheatsheets."; 79 | return 1; 80 | fi 81 | 82 | read "answer?cs: are you sure you want to remove the '${1}' cheatsheet? [y/N]: "; 83 | 84 | if [[ "${answer:u}" == "Y" || "${answer:u}" == "YES" ]]; then 85 | shred -un 10 $sheet && echo "cs: cheatsheet removed -- '${1}'"; 86 | return 0; 87 | fi 88 | echo "cs: no cheatsheets were removed"; 89 | } 90 | 91 | function __cs_edit_cheatsheet() { 92 | # $1 is sheet name 93 | [ -z $1 ] && echo "cs: you must provide a cheatsheet name" && return 1; 94 | 95 | local sheet="${__CS_SHEETS}/${1}" 96 | 97 | if [ ! -f $sheet ]; then 98 | echo "cs: cheatsheet does not exist -- '${1}'"; 99 | echo "Try 'cs list' to get a list of existing cheatsheets."; 100 | return 1; 101 | fi 102 | 103 | $__CS_EDITOR $sheet 104 | } 105 | 106 | function __cs_list_cheatsheets() { 107 | ls $__CS_SHEETS | sort 108 | } 109 | 110 | function cs() { 111 | case "$1" in 112 | "help"|"-h"|"--help") 113 | __cs_help 114 | ;; 115 | "add"|"-a"|"--add"|"create"|"-c"|"--create") 116 | __cs_add_cheatsheet $2 117 | ;; 118 | "edit"|"-e"|"--edit") 119 | __cs_edit_cheatsheet $2 120 | ;; 121 | "remove"|"rm"|"-r"|"--remove"|"del"|"delete"|"-d"|"--delete"|"--del") 122 | __cs_remove_cheatsheet $2 123 | ;; 124 | "list"|"show"|"ls"|"-l"|"--list") 125 | __cs_list_cheatsheets 126 | ;; 127 | *) 128 | __cs_display_cheatsheet $1 129 | ;; 130 | esac 131 | } 132 | --------------------------------------------------------------------------------