From 676c5f3b5aa7ed6c9a94456f5d446d71221158c3 Mon Sep 17 00:00:00 2001 From: Mehmet Tekman Date: Sun, 27 Aug 2017 02:57:08 +0100 Subject: [PATCH] org mode manager --- plugins/org-mode-manager/README.md | 22 ++++++++++ plugins/org-mode-manager/_org | 28 ++++++++++++ plugins/org-mode-manager/orgnotes.sh | 65 ++++++++++++++++++++++++++++ 3 files changed, 115 insertions(+) create mode 100644 plugins/org-mode-manager/README.md create mode 100644 plugins/org-mode-manager/_org create mode 100644 plugins/org-mode-manager/orgnotes.sh diff --git a/plugins/org-mode-manager/README.md b/plugins/org-mode-manager/README.md new file mode 100644 index 00000000..34e16f90 --- /dev/null +++ b/plugins/org-mode-manager/README.md @@ -0,0 +1,22 @@ +# org-mode-manager + +This plugin defines a function `org` that provides a tree-like representation of [org-mode](http://orgmode.org/) files in a user configured directory. + +#### Usage: + + org [--remove] + +#### Example usage: + + org tulip + # tulip.org is created + # + org banana --remove + # banana.org is removed + # + org flowers/colorful/tulip + # tulip.org is created at path flowers/colorful + # in the user directory + # + +The `.org` extension is automatically added if not specified. diff --git a/plugins/org-mode-manager/_org b/plugins/org-mode-manager/_org new file mode 100644 index 00000000..597990b2 --- /dev/null +++ b/plugins/org-mode-manager/_org @@ -0,0 +1,28 @@ +#compdef org + +_org(){ + local state + + local f_dirname=~/.config/org_notes.location + touch $f_dirname + + local f_dir=$(cat $f_dirname) + if [ "$f_dir" = "" ]; then + echo -e "-> No location set in $f_dirname" + return -1 + fi + + local f_dir=$(readlink -f $f_dir) + + _arguments \ + '1: :->org_files'\ + '*: :->args' + + local frels=$(find ${f_dir} -name '*.org' | sed "s|^${f_dir}/||" | sed "s|.org$||") + + case $state in + (org_files) _arguments "1:files:($frels)" ;; + esac +} + +_org "$@" diff --git a/plugins/org-mode-manager/orgnotes.sh b/plugins/org-mode-manager/orgnotes.sh new file mode 100644 index 00000000..1922149a --- /dev/null +++ b/plugins/org-mode-manager/orgnotes.sh @@ -0,0 +1,65 @@ +#!/bin/bash + +org(){ + local org_loc=~/.config/org_notes.location + + if ! [ -e $org_loc ] || [ "$(cat $org_loc)" = "" ];then + echo "Cannot find orgnotes git location. Please set the location in the file: + $org_loc +or run the install script." + return -1 + fi + + local org_dir=$(cat $org_loc) + + local file=$1 + local delete=$2 + + case $file in + "") + #tree $(cat $org_loc) | grep -v '~' | sed "s||"; + tree -CD -I '*~' -rt $org_dir\ + | sed "s|${org_dir}|\nYou have the following org-mode notes:\n|"\ + | sed -r 's|([^[].*)\s(\[.*\])\s(.*)|\t\2\t\1\3|' + + return -1; + ;; + -h);; + --help) + echo " + `basename $0` [--delete] + +Generates an org-notes file in a folder location set in the $org_loc file +"; + return -1; + ;; + esac + + if [[ "$delete" =~ "--" ]]; then + [ "$delete" != "--delete" ] && echo "Unable to parse: $delete" && return -1 + fi + + local ext=$( echo $file | awk -F'.' '{print $NF}' ) + + [ "$ext" != ".org" ] && file=${file}.org + + if [ "$delete" = "--delete" ]; then + local eloc=$org_dir/$file + + if [ -e $eloc ]; then + echo -n "Remove $file? [y/n] "; read ans; + [ "$ans" = "y" ] && rm $eloc && echo "Deleted." + else + echo "Cannot find $file. Aborting." + fi + else + local dirn=`dirname $file` + mkdir -p $org_dir/$dirn + + emacs $org_dir/$file + fi +} + +#fpath=(~/.zsh/completion $fpath) +autoload -U compinit +compinit