SHOW:
|
|
- or go back to the newest paste.
| 1 | - | #! /bin/bash |
| 1 | + | #! /bin/bash -e |
| 2 | # | |
| 3 | # Simple notes | |
| 4 | # Author: Victor Ananjevsky <[email protected]>, 2010 | |
| 5 | # http://code.google.com/p/yad/wiki/Notes | |
| 6 | # | |
| 7 | # Meus comandos a 2 cliques ;-) | |
| 8 | # Author: rai3mb | |
| 9 | # http://www.vivaolinux.com.br/artigo/Yad-016-Eu-quero-sempre-mais-de-ti?pagina=10 | |
| 10 | # | |
| 11 | # Secret notes | |
| 12 | # Author: Alysson Gonçalves <[email protected]>, 2012 | |
| 13 | # | |
| 14 | # Armazena notas de forma segura (criptografada). | |
| 15 | # local onde é salvo os progromas: ~/.cache/secret_notes/ | |
| 16 | - | # Cria uma pasta chamada notes no dir de cache do usuário |
| 16 | + | # Requer: |
| 17 | - | export dir_notes="${XDG_CACHE_HOME:-$HOME/.cache}/notes"
|
| 17 | + | # yad (interface grafica), gpg (programa de criptografia) |
| 18 | - | [ -e $dir_notes ] || mkdir -p $dir_notes |
| 18 | + | |
| 19 | ||
| 20 | - | export notes_hist=$dir_notes/notes.hist |
| 20 | + | function _main() {
|
| 21 | - | [ -e $notes_hist ] || touch $notes_hist |
| 21 | + | |
| 22 | # Cria uma pasta chamada notes no dir de cache do usuário | |
| 23 | - | export temp_pipe=/tmp/notes.$$ |
| 23 | + | export dir_notes="${XDG_CACHE_HOME:-$HOME/.cache}/secret_notes"
|
| 24 | - | [ -p $temp_pipe ] || mkfifo $temp_pipe |
| 24 | + | [ -e $dir_notes ] || mkdir -p $dir_notes |
| 25 | - | trap "rm -f $temp_pipe" EXIT |
| 25 | + | |
| 26 | - | exec 3<> $temp_pipe |
| 26 | + | export notes_hist=$dir_notes/secret_notes.hist |
| 27 | [ -e $notes_hist ] || touch $notes_hist | |
| 28 | ||
| 29 | export temp_pipe=/tmp/secret_notes.$$ | |
| 30 | [ -p $temp_pipe ] || mkfifo $temp_pipe | |
| 31 | trap "rm -f $temp_pipe" 1 2 3 15 | |
| 32 | exec 3<> $temp_pipe | |
| 33 | ||
| 34 | _menu_atualizar | |
| 35 | yad --notification --image='tag-new' --text="Secret notes" --listen <&3 2>- | |
| 36 | ||
| 37 | rm -f $temp_pipe | |
| 38 | } | |
| 39 | - | --window-icon="text-editor" --filename="$file_note" --editable \ |
| 39 | + | |
| 40 | - | --button="gtk-save:0" --button="gtk-close:1" > $tmpfile |
| 40 | + | |
| 41 | function _abrir() {
| |
| 42 | ||
| 43 | - | mv $tmpfile $file_note |
| 43 | + | |
| 44 | [ -e $file_note ] || return | |
| 45 | ||
| 46 | # Cria arquivo temporário para fins diversos | |
| 47 | tmpfile=$(mktemp --tmpdir notes_new-$$.XXX) | |
| 48 | - | echo -e "$hist\n`grep -v "$hist" $notes_hist`" | head -5 > $tmpfile |
| 48 | + | |
| 49 | # Verifica se o arquivo é novo | |
| 50 | conteudo= | |
| 51 | if [ "$2" != "novo" ]; then | |
| 52 | conteudo="$(gpg --decrypt $file_note)" | |
| 53 | fi | |
| 54 | yad --text-info --title=${file_note##*/} --show-uri --geometry=400x200-0-0 \
| |
| 55 | --window-icon="text-editor" --editable \ | |
| 56 | --button="gtk-save:0" --button="gtk-close:1" \ | |
| 57 | <<< "$conteudo" > $tmpfile | |
| 58 | # --filename="$file_note" | |
| 59 | ||
| 60 | # Salva as alterações no arquivo temporário e depois salva no arquivo original | |
| 61 | ||
| 62 | ||
| 63 | if [[ $? -eq 0 ]]; then | |
| 64 | #mv $tmpfile $file_note | |
| 65 | cat $tmpfile | gpg --symmetric --pgp8 --cipher-algo AES256 > "$file_note" | |
| 66 | fi | |
| 67 | ||
| 68 | # Salva o histórico de notas | |
| 69 | hist="${file_note##*/}!bash -c '_abrir \"$file_note\"'"
| |
| 70 | - | _abrir "$note_new" |
| 70 | + | echo -e "\n$hist`grep -v "$hist" $notes_hist`" | head -5 > $tmpfile |
| 71 | mv $tmpfile $notes_hist | |
| 72 | ||
| 73 | rm $tmpfile | |
| 74 | _menu_atualizar | |
| 75 | } | |
| 76 | export -f _abrir | |
| 77 | ||
| 78 | ||
| 79 | function _menu_criar() {
| |
| 80 | file_name=$(yad --image=document-new --title="Nova anotação" --text="Digite o nome da anotação" --entry --editable) | |
| 81 | [[ -z "$file_name" ]] && return | |
| 82 | ||
| 83 | note_new="$dir_notes/$file_name.note" | |
| 84 | # Verifica se existe algum arquivo com o mesmo nome digitado e se sim, pergunta se deseja abri-lo | |
| 85 | if [[ -e "$note_new" ]]; then | |
| 86 | yad --image=dialog-question --title="Confirmação" \ | |
| 87 | --text="Existe esse arquivo. Deseja abri-lo?" \ | |
| 88 | - | menu="menu:Novo!bash -c '_menu_criar'|Abrir!bash -c '_menu_abrir'||"; |
| 88 | + | |
| 89 | [[ $? -eq 1 ]] && return | |
| 90 | else | |
| 91 | touch $note_new | |
| 92 | fi | |
| 93 | _abrir "$note_new" "novo" | |
| 94 | } | |
| 95 | export -f _menu_criar | |
| 96 | ||
| 97 | - | _menu_atualizar |
| 97 | + | |
| 98 | - | yad --notification --image='tag-new' --text="Secret notes" --listen <&3 2>- & |
| 98 | + | |
| 99 | ||
| 100 | file_name=$(yad --file --title="Abrir anotação" --image=document-open --geometry=700x500 --filename="$dir_notes/" --file-filter="Notes files|*.note") | |
| 101 | [[ -z "$file_name" ]] && return | |
| 102 | ||
| 103 | _abrir "$file_name" | |
| 104 | ||
| 105 | } | |
| 106 | export -f _menu_abrir | |
| 107 | ||
| 108 | function _menu_atualizar() {
| |
| 109 | exec 3<> $temp_pipe | |
| 110 | ||
| 111 | menu="menu:Novo!bash -c '_menu_criar'|Abrir!bash -e -c '_menu_abrir'|"; | |
| 112 | menu="$menu`egrep -v '^#' $notes_hist | tr '\n' '|'`" | |
| 113 | menu="$menu|Fechar!quit" | |
| 114 | echo $menu >&3 | |
| 115 | ||
| 116 | } | |
| 117 | export -f _menu_atualizar | |
| 118 | ||
| 119 | _main & |