Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #! /bin/bash
- #
- # Simple notes
- # Author: Victor Ananjevsky <ananasik@gmail.com>, 2010
- # http://code.google.com/p/yad/wiki/Notes
- #
- # Meus comandos a 2 cliques ;-)
- # Author: rai3mb
- # http://www.vivaolinux.com.br/artigo/Yad-016-Eu-quero-sempre-mais-de-ti?pagina=10
- #
- # Secret notes
- # Author: Alysson Gonçalves <agalysson@gmail.com>, 2012
- #
- # Cria uma pasta chamada notes no dir de cache do usuário
- export dir_notes="${XDG_CACHE_HOME:-$HOME/.cache}/notes"
- [ -e $dir_notes ] || mkdir -p $dir_notes
- export notes_hist=$dir_notes/notes.hist
- [ -e $notes_hist ] || touch $notes_hist
- export temp_pipe=/tmp/notes.$$
- [ -p $temp_pipe ] || mkfifo $temp_pipe
- trap "rm -f $temp_pipe" EXIT
- exec 3<> $temp_pipe
- # Função responsável por abrir a nota
- function _abrir() {
- file_note=$1
- [ -e $file_note ] || return
- # Cria arquivo temporário para fins diversos
- tmpfile=$(mktemp --tmpdir notes_new-$$.XXX)
- # Salva as alterações no arquivo temporário e depois salva no arquivo original
- yad --text-info --title=${file_note##*/} --show-uri --geometry=400x200-0-0 \
- --window-icon="text-editor" --filename="$file_note" --editable \
- --button="gtk-save:0" --button="gtk-close:1" > $tmpfile
- if [[ $? -eq 0 ]]; then
- mv $tmpfile $file_note
- fi
- # Salva o histórico de notas
- hist="${file_note##*/}!bash -c '_abrir \"$file_note\"'"
- echo -e "$hist\n`grep -v "$hist" $notes_hist`" | head -5 > $tmpfile
- mv $tmpfile $notes_hist
- _menu_atualizar
- }
- export -f _abrir
- function _menu_criar() {
- file_name=$(yad --image=document-new --title="Nova anotação" --text="Digite o nome da anotação" --entry --editable)
- [[ -z "$file_name" ]] && return
- note_new="$dir_notes/$file_name.note"
- # Verifica se existe algum arquivo com o mesmo nome digitado e se sim, pergunta se deseja abri-lo
- if [[ -e "$note_new" ]]; then
- yad --image=dialog-question --title="Confirmação" \
- --text="Existe esse arquivo. Deseja abri-lo?" \
- --button="gtk-yes:0" --button="gtk-no:1"
- [[ $? -eq 1 ]] && return
- else
- touch $note_new
- fi
- _abrir "$note_new"
- }
- export -f _menu_criar
- function _menu_abrir() {
- file_name=$(yad --file --title="Abrir anotação" --image=document-open --geometry=700x500 --filename="$dir_notes/" --file-filter="Notes files|*.note")
- [[ -z "$file_name" ]] && return
- _abrir "$file_name"
- }
- export -f _menu_abrir
- function _menu_atualizar() {
- exec 3<> $temp_pipe
- menu="menu:Novo!bash -c '_menu_criar'|Abrir!bash -c '_menu_abrir'||";
- menu="$menu`egrep -v '^#' $notes_hist | tr '\n' '|'`"
- menu="$menu|Fechar!quit"
- echo $menu >&3
- }
- export -f _menu_atualizar
- _menu_atualizar
- yad --notification --image='tag-new' --text="Secret notes" --listen <&3 2>- &
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement