org mode manager
This commit is contained in:
parent
d848c94804
commit
676c5f3b5a
22
plugins/org-mode-manager/README.md
Normal file
22
plugins/org-mode-manager/README.md
Normal file
@ -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 <file> [--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.
|
28
plugins/org-mode-manager/_org
Normal file
28
plugins/org-mode-manager/_org
Normal file
@ -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 "$@"
|
65
plugins/org-mode-manager/orgnotes.sh
Normal file
65
plugins/org-mode-manager/orgnotes.sh
Normal file
@ -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` <filename> [--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
|
Loading…
Reference in New Issue
Block a user