├── README.md ├── ddnotes └── screenshots ├── create-new.png ├── listing.png └── notewindow.png /README.md: -------------------------------------------------------------------------------- 1 | # ddnotes - drop down notes 2 | 3 | DDNotes opens a drop down terminal window to edit your notes. 4 | 5 | ![notes](https://raw.githubusercontent.com/umurgdk/ddnotes/master/screenshots/notewindow.png) 6 | 7 | ## Features 8 | 9 | * Listing notes with dmenu 10 | * Creating new notes with dmenu 11 | * Open/Hide last opened note with `ddnotes last` 12 | 13 | ## Dependencies 14 | 15 | * `xdotools` 16 | * `wmutils` 17 | * `dmenu` 18 | * `bash` 19 | * An editor application which supports setting custom window titles. Most of the terminal emulators are supporting custom titles with a custom command to run (e.g vim). Otherwise this script should be able to work with GUI applications too. 20 | 21 | ## Usage 22 | 23 | Right now the terminal emulator is hardcoded in the script, so you have to change it yourself by editing the file. You need to make sure the editor application (e.g terminal emulator) can be run with custom title argument. ddnotes depending on custom window titles. 24 | 25 | ```bash 26 | $ mkdir ~/notes 27 | 28 | # Show a list of notes with dmenu to open or create 29 | $ ddnotes 30 | 31 | # Open/Toggle the last opened note window 32 | $ ddnotes last 33 | 34 | # Open ddnotes with different notes folder 35 | $ NOTES_DIR=$HOME/secret/notes ddnotes 36 | ``` 37 | 38 | ### Configuring `i3wm` 39 | 40 | You need to configure `i3wm` to always keep note windows as floating. This way this script can change to size and position freely. Since I don't know the configurations of other tiling window managers please checkout their documentations to how to define floating rules for windows. 41 | 42 | Add this line to your i3 configuration file. If you want to keep borders delete the part `border none` 43 | 44 | ``` 45 | for_window [title="^notes:"] floating enable border none 46 | ``` 47 | 48 | ## Screenshots 49 | 50 | ![listing](https://raw.githubusercontent.com/umurgdk/ddnotes/master/screenshots/listing.png) 51 | ![create new](https://raw.githubusercontent.com/umurgdk/ddnotes/master/screenshots/create-new.png) 52 | -------------------------------------------------------------------------------- /ddnotes: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | #set -o xtrace 3 | NOTES_DIR=${NOTES_DIR:-$HOME/notes} 4 | MENU_ITEMS=`find $NOTES_DIR -type f -name \*.md -not -name ".*" -exec basename {} .md \;` 5 | 6 | IFS=' ' read -r -a ROOT_SIZE <<< $(wattr wh $(lsw -r)) 7 | ROOT_W_HALF=`expr ${ROOT_SIZE[0]} / 2` 8 | 9 | NOTE_WIN= 10 | NOTE_NAME= 11 | 12 | function open_or_create_note() { 13 | if [[ -z "${NOTE_NAME// }" ]]; then 14 | exit 15 | fi 16 | 17 | if [[ ! -f $NOTES_DIR/$NOTE_NAME.md ]]; then 18 | echo "" | dmenu -p "$NOTE_NAME does not exist, would you like to create? [Ent/Esc]" 19 | if [[ $? -eq 0 ]]; then 20 | touch $NOTES_DIR/$NOTE_NAME.md; 21 | open_note; 22 | echo $NOTE_NAME > $NOTES_DIR/.last 23 | fi 24 | else 25 | find_win; 26 | if [[ -z $NOTE_WIN ]]; then 27 | open_note; 28 | else 29 | toggle_win; 30 | fi 31 | echo $NOTE_NAME > $NOTES_DIR/.last 32 | fi 33 | } 34 | 35 | function ask_note_name() { 36 | NOTE_NAME=`cat <<< $MENU_ITEMS | dmenu -p "Notes:"` 37 | } 38 | 39 | function to_hex() { 40 | bc <<< "obase=16; $1" | sed -e 's/^/0x/' 41 | } 42 | 43 | function find_win() { 44 | NOTE_WIN=${NOTE_WIN:-$(xdotool search --name notes:$NOTE_NAME)} 45 | } 46 | 47 | function resizewin() { 48 | WIN_WIDTH=$(expr ${ROOT_SIZE[0]} / 2) 49 | WIN_HEIGHT=$(expr ${ROOT_SIZE[1]} / 3) 50 | 51 | xdotool windowsize $NOTE_WIN $WIN_WIDTH $WIN_HEIGHT 52 | } 53 | 54 | function centerx() { 55 | X=$(expr $ROOT_W_HALF - $(wattr w $(to_hex $NOTE_WIN)) / 2) 56 | xdotool windowmove $NOTE_WIN $X 0 57 | } 58 | 59 | function toggle_win() { 60 | wattr m $(to_hex $NOTE_WIN) 61 | if [ $? -eq 0 ]; then 62 | xdotool windowunmap $NOTE_WIN; 63 | else 64 | resizewin; 65 | centerx; 66 | xdotool windowmap $NOTE_WIN; 67 | fi 68 | } 69 | 70 | function open_note() { 71 | alacritty \ 72 | --class notes \ 73 | --config-file $HOME/.config/alacritty/alacritty.yml \ 74 | -d 80 25 \ 75 | -t notes:$NOTE_NAME \ 76 | -e vim $NOTES_DIR/$NOTE_NAME.md & 77 | 78 | sleep 0.3; 79 | 80 | find_win; 81 | resizewin; 82 | centerx; 83 | } 84 | 85 | case $1 in 86 | last) 87 | if [[ -f $NOTES_DIR/.last ]]; then 88 | NOTE_NAME=`cat $NOTES_DIR/.last`; 89 | else 90 | ask_note_name; 91 | fi 92 | open_or_create_note; 93 | ;; 94 | *) 95 | ask_note_name; 96 | open_or_create_note; 97 | esac 98 | -------------------------------------------------------------------------------- /screenshots/create-new.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/umurgdk/ddnotes/b0eb01bd22fa7f826b14b9b56ae5936524bbe3b1/screenshots/create-new.png -------------------------------------------------------------------------------- /screenshots/listing.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/umurgdk/ddnotes/b0eb01bd22fa7f826b14b9b56ae5936524bbe3b1/screenshots/listing.png -------------------------------------------------------------------------------- /screenshots/notewindow.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/umurgdk/ddnotes/b0eb01bd22fa7f826b14b9b56ae5936524bbe3b1/screenshots/notewindow.png --------------------------------------------------------------------------------