1
0
mirror of https://git.envs.net/envs/burrow.git synced 2024-06-14 05:16:42 +00:00

added gophermap editing with awesome bash completion

This commit is contained in:
James Tomasino 2018-09-24 21:35:36 -04:00
parent f0f21df913
commit 487574e053
4 changed files with 74 additions and 127 deletions

View File

@ -21,35 +21,19 @@ See the [Getting Started](https://github.com/jamestomasino/burrow/wiki/Getting-S
```bash
burrow phlog # create new phlog post
burrow recipe # add or update a recipe to box
burrow topic # add or update a topic file
burrow gophermap # edit a gophermap
burrow rss # generate a RSS feed of phlog entries
burrow create-config # generate a default config file
burrow edit-config # open your config file for editing
burrow update-git # pull latest git repo for gopher dir, if exists
```
- `create-config` will auto-generate a configuration file at
`$HOME/.config/burrow/config`. It will be populated by the default parameters
listed below and provide an easy way to customize your configuration. At a
minimum you should update your `config_dir_gopher` to point to the folder on
your local computer where your gopher hole resides.
- `edit-config` will open your burrow configuration file for easy editing.
- `phlog` will prompt for the title of a new post, then open it in your default
`$EDITOR`. By default it will provide you a template, but you can override this
by including a `.template` file in your phlog directory.
- `recipe` will prompt for the name of your recipe, then open it in your default
`$EDITOR`. By default it will provide you a template, but you can override this
by including a `.template` file in your recipe box directory.
- `topic` will prompt for the name of the topic, then open it in your default
`$EDITOR`. By default it will provide you a template, but you can override this
by including a `.template` file in your topics directory.
- `root` will open your gopher hole's root gophermap for editing. This will
- `gophermap` will open a gophermap file for editing. This will
remove any `type i` formatting and allow comments to be added in natural text.
You will still need to create links in the proper gophermap formatting.
@ -85,14 +69,6 @@ config_dir_phlog="phlog" # relative path to phlog
config_phlog_gophermap=true # phlogs use gophermap format by default
config_phlog_usedate=true # use a date-stamp on phlog posts
config_dir_recipebox="recipebox" # relative path to recipe box
config_recipebox_gophermap=false # recipes use plain text by default
config_recipebox_usedate=false # do not use a date-stamp on recipe filenames
config_dir_topics="topics" # relative path to topics directory
config_topics_gophermap=true # topic notes use gophermap format by default
config_topics_usedate=false # do not use a date-stamp on topic filenames
config_git_commit=false # automatically commit changes if git repo
config_git_push=false # automatically push changes if git repo

110
burrow
View File

@ -1,23 +1,17 @@
#!/bin/sh
version="v1.6.1"
version="v1.7.0"
configfiles="$HOME/.config/burrow/config $HOME/.config/burrow $HOME/.burrow"
# vars from config
config_dir_gopher="$HOME/gopher/"
config_dir_recipebox="recipebox"
config_dir_phlog="phlog"
config_dir_topics="topics"
config_gopher_server="sdf.org"
config_gopher_port="70"
config_gopher_root="/users/username/"
config_phlog_gophermap=true
config_phlog_usedate=true
config_recipebox_gophermap=false
config_recipebox_usedate=false
config_topics_gophermap=true
config_topics_usedate=false
config_git_commit=false
config_git_push=false
config_autoindent=true
@ -41,14 +35,12 @@ flag_help=0
# vars from args
arg_options="hvd"
arg_shortlist=0
arg_recipe=0
arg_gopherdir=0
arg_phlog=0
arg_topic=0
arg_create_config=0
arg_edit_config=0
arg_update_git=0
arg_rss=0
arg_root=0
arg_gophermap=""
# silence directory movements
push_d () {
@ -65,11 +57,8 @@ burrow [options] [commands]
COMMANDS:
phlog Create new phlog entry
recipe Add new recipe to box
topic Add or update a topic
root Edit your root gophermap
gophermap Edit a gophermap
rss Generate an rss feed of recent phlog entries
create-config Create a default configuration file
edit-config Edit your configuration file
update-git Silently pulls gopher git repo if it exists
@ -133,20 +122,39 @@ parse_input () {
esac
done
for arg in "$@"; do
argc=$(printf "%s" "$arg" | tr '[:upper:]' '[:lower:]')
while test $# -gt 0
do
argc=$(printf "%s" "$1" | tr '[:upper:]' '[:lower:]')
case $argc in
"shortlist") arg_shortlist=1 ;;
"phlog") arg_phlog=1 ;;
"recipe") arg_recipe=1 ;;
"topic") arg_topic=1 ;;
"create-config") arg_create_config=1 ;;
"edit-config") arg_edit_config=1 ;;
"update-git") arg_update_git=1 ;;
"rss") arg_rss=1 ;;
"root") arg_root=1 ;;
*) printf "Unknown command: %s\\n" "$arg";;
"shortlist")
arg_shortlist=1
;;
"gophermap")
if [ $# -gt 1 ]; then
shift
arg_gophermap="$1"
else
arg_gophermap="/"
fi
;;
"phlog")
arg_phlog=1
;;
"gopherdir")
arg_gopherdir=1
;;
"edit-config")
arg_edit_config=1
;;
"update-git")
arg_update_git=1
;;
"rss")
arg_rss=1
;;
*) printf "Unknown command: %s\\n" "$argc";;
esac
shift
done
}
@ -547,7 +555,6 @@ create_config () {
if [ ! -f "$HOME/.config/burrow/config" ] && \
[ ! -f "$HOME/.config/burrow" ] && \
[ ! -f "$HOME/.burrow" ]; then
config="$HOME/.config/burrow/config"
mkdir -p "$(dirname "$config")"
{
@ -562,14 +569,6 @@ create_config () {
printf "config_phlog_usedate=true\\n"
printf "config_phlog_autorss=false\\n"
printf "\\n"
printf "config_dir_recipebox=\"recipebox\"\\n"
printf "config_recipebox_gophermap=false\\n"
printf "config_recipebox_usedate=false\\n"
printf "\\n"
printf "config_dir_topics=\"topics\"\\n"
printf "config_topics_gophermap=true\\n"
printf "config_topics_usedate=false\\n"
printf "\\n"
printf "config_git_commit=false\\n"
printf "config_git_push=false\\n"
printf "\\n"
@ -580,8 +579,6 @@ create_config () {
printf "config_gopher_desc=\"Gopher Hole Description\"\\n"
printf "config_rss_num_entries=\"10\"\\n"
} >> "$config"
else
printf "Configuration already exists.\\n"
fi
}
@ -598,7 +595,7 @@ main () {
parse_input "$@"
if [ $arg_shortlist -gt 0 ]; then
out="phlog topic recipe rss edit-config create-config update-git -v -h -d"
out="phlog gophermap rss edit-config update-git -v -h -d"
die "${out}" 0
fi
@ -614,11 +611,8 @@ main () {
set -x
fi
if [ $arg_create_config -gt 0 ]; then
create_config
fi
if [ $arg_edit_config -gt 0 ]; then
create_config
edit_config
fi
@ -628,42 +622,28 @@ main () {
fi
done
if [ $arg_gopherdir -gt 0 ]; then
die "${config_dir_gopher}" 0
fi
if [ $arg_update_git -gt 0 ]; then
update_git
fi
if [ $arg_root -gt 0 ]; then
if [ "$arg_gophermap" != "" ]; then
# If we don't have a gophermap, create one to avoid
# accidentally sorting the file on first-time generation
if [ ! -f "${config_dir_gopher}gophermap" ]; then
touch "${config_dir_gopher}gophermap"
if [ ! -f "${config_dir_gopher}${arg_gophermap}gophermap" ]; then
touch "${config_dir_gopher}${arg_gophermap}gophermap"
fi
make_post "" \
"" \
"${arg_gophermap}" \
true \
false \
true \
false
fi
if [ $arg_recipe -gt 0 ]; then
make_post "What is the name of your recipe? " \
"$config_dir_recipebox" \
"$config_recipebox_gophermap" \
"$config_recipebox_usedate" \
true \
false
fi
if [ $arg_topic -gt 0 ]; then
make_post "What is the name of your topic? " \
"$config_dir_topics" \
"$config_topics_gophermap" \
"$config_topics_usedate" \
true \
false
fi
if [ $arg_phlog -gt 0 ]; then
make_post "Enter a title for your post: " \
"$config_dir_phlog" \

View File

@ -1,4 +1,4 @@
.TH BURROW 1 "01 Sep 2018" "version 1.6.1"
.TH BURROW 1 "24 Sep 2018" "version 1.7.0"
.SH NAME
burrow \- a helper for building and managing a gopher hole
.SH SYNOPSIS
@ -15,39 +15,16 @@ by including a
.I .template
file in your phlog directory.
.TP
.B recipe
Prompt for the name of your recipe, then open it in your default
$EDITOR. By default it will provide you a template, but you can override this
by including a
.I .template
file in your recipe box directory.
.TP
.B topic
Prompt for the name of the topic, then open it in your default
$EDITOR. By default it will provide you a template, but you can override this
by including a
.I .template
file in your topics directory.
.TP
.B root
Open your gopher hole's root gophermap for editing. This will remove any
type 'i' formatting and allow comments to be added in natural text. You will
still need to create links in the proper gophermap formatting.
.B gophermap
Open a gophermap file relative to your gopher directory for editing,
automatically stripping some special characters for easier editing of info
lines.
.TP
.B rss
Automatically generate an RSS feed of your most recent phlog
entries and output it to the root of your gopher directory. This can be
automatically generated by using the config option config_phlog_autorss.
.TP
.B create-config
Auto-generate a configuration file at
.I $HOME/.config/burrow/config.
It will be populated by the default parameters
listed below and provide an easy way to customize your configuration. At a
minimum you should update your
.I config_dir_gopher
to point to the folder on your local computer where your gopher hole resides.
.TP
.B edit-config
Opens your burrow configuration file for editing if it exists.
.TP

View File

@ -2,21 +2,35 @@
_burrow()
{
# Get basic autocomplete commands from the function itself
local helplist
helplist=$(burrow shortlist)
# Combine all the lists for autocomplete
local cur
cur=${COMP_WORDS[COMP_CWORD]}
COMPREPLY=( $( compgen -W "$helplist" -- "$cur" ) )
if [ "${COMP_WORDS[1]}" == "gophermap" ]; then
local gopher_dir
local gophermaps
local directories
gopher_dir=$(burrow gopherdir)
search_dir=${gopher_dir}
if [ -n "${COMP_WORDS[2]}" ]; then
if [ -d "${gopher_dir}${COMP_WORDS[2]}" ]; then
search_dir="${gopher_dir}${COMP_WORDS[2]}"
fi
fi
gophermaps=$(find "$search_dir" -mindepth 1 -maxdepth 1 -type f -name "gophermap" -print | sed "s|$gopher_dir||" | sed "s|gophermap$||" )
directories=$(find "$search_dir" -mindepth 1 -maxdepth 1 -type d -print | sed "s|$gopher_dir||" )
COMPREPLY=( $( compgen -W "$gophermaps $directories" -- "$cur" ) )
else
local helplist
helplist=$(burrow shortlist)
COMPREPLY=( $( compgen -W "$helplist" -- "$cur" ) )
fi
}
# Detect if current shell is ZSH, and if so, load this file in bash
# compatibility mode.
if [ -n "$ZSH_VERSION" ]; then
autoload bashcompinit
bashcompinit
autoload bashcompinit
bashcompinit
fi
complete -o default -o nospace -F _burrow burrow
@ -25,5 +39,5 @@ complete -o default -o nospace -F _burrow burrow
# when the user has tab-completed the executable name and consequently
# included the '.exe' suffix.
if [ Cygwin = "$(uname -o 2>/dev/null)" ]; then
complete -o default -o nospace -F _burrow burrow.exe
complete -o default -o nospace -F _burrow burrow.exe
fi