mirror of https://git.envs.net/envs/burrow.git
Compare commits
144 Commits
Author | SHA1 | Date |
---|---|---|
~creme | 53c02830c0 | |
James Tomasino | 459de8117e | |
creme | 6a8bbc71de | |
James Tomasino | b83e5056f1 | |
Zachary Lee Andrews | 91d6113fe3 | |
Sven | 2556d9eb40 | |
James Tomasino | 33c1aa0437 | |
creme | af7d8a31c2 | |
creme | 2b99bf98e3 | |
James Tomasino | 8658c7675c | |
creme | 404cd61586 | |
James Tomasino | 478f40ce24 | |
creme | b80a1c6789 | |
creme | 4b3d7364f9 | |
James Tomasino | 8e900ca005 | |
James Tomasino | e6442c9d6f | |
James Tomasino | 4c011fc82e | |
David Harrison | b9a2650819 | |
Munchotaur | d3289ebc94 | |
Munchotaur | 4a01b598fb | |
James Tomasino | 05021a7699 | |
James Tomasino | d83843fba6 | |
fosslinux | e671238848 | |
James Tomasino | 0b915075e5 | |
James Tomasino | f31b5ae218 | |
James Tomasino | cf9e56cc3c | |
James Tomasino | e71e2ae579 | |
James Tomasino | 84cc1efcd5 | |
James Tomasino | 045e7b8f72 | |
James Tomasino | 7782fd066d | |
James Tomasino | 39bd2c500a | |
James Tomasino | 08d172b3f9 | |
James Tomasino | 22387cc6fe | |
James Tomasino | 9f4a61b4f9 | |
James Tomasino | b646c085c1 | |
James Tomasino | 982eb95372 | |
James Tomasino | 9b6f3daeb1 | |
James Tomasino | 1c66e9297d | |
Jelle Besseling | c2eea80929 | |
James Tomasino | b6e2d6efa6 | |
James Tomasino | 95c008c31a | |
James Tomasino | 4cd0a9f498 | |
Samuel Tyler | 52ace7f214 | |
Samuel Tyler | 21688e4fd9 | |
James Tomasino | 49110809c1 | |
James Tomasino | 7158d5eae9 | |
James Tomasino | dd3a7d08d1 | |
James Tomasino | 2518e999af | |
James Tomasino | b715b663ff | |
Stephen Tudor | 516f835ad3 | |
Stephen Tudor | a8ec4d6c57 | |
Paco Esteban | d890a6ef53 | |
James Tomasino | 29253bc254 | |
James Tomasino | 7cd512a082 | |
James Tomasino | fc49cbeb90 | |
James Tomasino | d9a4f0169e | |
James Tomasino | 2cfeda0340 | |
James Tomasino | 3fed90daef | |
James Tomasino | 487574e053 | |
James Tomasino | f0f21df913 | |
Jelle Besseling | 986f3df957 | |
James Tomasino | 6dce0f1924 | |
James Tomasino | d37369df53 | |
James Tomasino | e3f15046b2 | |
James Tomasino | e81fa7d8bd | |
James Tomasino | 9b9377e401 | |
James Tomasino | 3e3bf3a552 | |
James Tomasino | 9b2e0221ca | |
James Tomasino | cbe6256862 | |
James Tomasino | e8c105a51c | |
James Tomasino | 23c2a9909f | |
James Tomasino | d2543cccab | |
James Tomasino | 28e1831369 | |
James Tomasino | 5366ac016b | |
James Tomasino | 93e1c41e9c | |
James Tomasino | 42892d8cfb | |
James Tomasino | 4d08e72352 | |
James Tomasino | 2acf982073 | |
James Tomasino | 6d29f54f93 | |
James Tomasino | 57eb27f8ad | |
James Tomasino | 2bc0894201 | |
James Tomasino | de865b1e5a | |
James Tomasino | 43f504e101 | |
James Tomasino | 2a693f66e5 | |
James Tomasino | 09b031157f | |
James Tomasino | c263bf8903 | |
James Tomasino | 34b61e9e3a | |
James Tomasino | 3d22e5d275 | |
James Tomasino | bc050454ff | |
James Tomasino | d79080ac1e | |
James Tomasino | 694e490353 | |
James Tomasino | 87ffadc19a | |
James Tomasino | 359dea788b | |
James Tomasino | b880efa992 | |
James Tomasino | 56f5c3f3f6 | |
James Tomasino | 7121dd0f29 | |
James Tomasino | 4535f8f571 | |
James Tomasino | fb193ff7b5 | |
James Tomasino | 4abc2496aa | |
James Tomasino | 3487b590ca | |
James Tomasino | 00707c3046 | |
James Tomasino | a7dc326a62 | |
James Tomasino | 488e27ea03 | |
James Tomasino | 445f6a30a9 | |
James Tomasino | e981106dcc | |
James Tomasino | 170817a1eb | |
James Tomasino | f49be1126e | |
James Tomasino | 43e903bbb6 | |
James Tomasino | 11d6b80757 | |
James Tomasino | 6c67e8f7fa | |
James Tomasino | 33ec590cfb | |
James Tomasino | 48f0f0ca0c | |
James Tomasino | 6f5bedded3 | |
James Tomasino | 3d5319afb0 | |
James Tomasino | 31bc38669f | |
James Tomasino | 416f8707b1 | |
James Tomasino | 6b683df3be | |
James Tomasino | 2403bedda8 | |
James Tomasino | b6ea90a866 | |
James Tomasino | ea10ed8356 | |
James Tomasino | 0ea68ff866 | |
James Tomasino | 496adcbf85 | |
James Tomasino | e0c264f6ce | |
James Tomasino | 7366097bf0 | |
James Tomasino | 95c1a61274 | |
James Tomasino | 2971b8a998 | |
James Tomasino | 6a00579db2 | |
James Tomasino | 39372f1d0c | |
James Tomasino | f41090af3e | |
James Tomasino | 09472ab21a | |
James Tomasino | 6ba34bf60f | |
James Tomasino | 78f3d4334d | |
James Tomasino | 6b7bc00308 | |
James Tomasino | b994822eac | |
James Tomasino | b2237e440f | |
James Tomasino | 085d5b43bc | |
James Tomasino | 4c60852713 | |
James Tomasino | e454e54c12 | |
James Tomasino | 3d1fafae7c | |
James Tomasino | 22dd803806 | |
James Tomasino | 078f626f96 | |
James Tomasino | 0b2437eb06 | |
James Tomasino | d0aab3267b | |
James Tomasino | eaa38f7d15 |
|
@ -0,0 +1,26 @@
|
|||
---
|
||||
kind: pipeline
|
||||
type: ssh
|
||||
name: deploy
|
||||
|
||||
server:
|
||||
host:
|
||||
from_secret: host
|
||||
user:
|
||||
from_secret: username
|
||||
ssh_key:
|
||||
from_secret: ssh_key
|
||||
|
||||
clone:
|
||||
disable: true
|
||||
|
||||
trigger:
|
||||
branch:
|
||||
- master
|
||||
|
||||
steps:
|
||||
- name: deploy
|
||||
commands:
|
||||
- cd /opt/services/burrow
|
||||
- sudo -Hu services git pull origin master
|
||||
- sudo -Hu root make
|
|
@ -0,0 +1,3 @@
|
|||
language: shell
|
||||
script:
|
||||
- bash -c 'shopt -s globstar && shellcheck burrow'
|
36
Makefile
36
Makefile
|
@ -1,33 +1,47 @@
|
|||
PREFIX ?= /usr/local
|
||||
BINDIR ?= $(PREFIX)/bin
|
||||
MANDIR ?= $(PREFIX)/share/man
|
||||
MANDIR ?= $(PREFIX)/share/man/man1
|
||||
|
||||
# Attempt to find bash completion dir in order of preference
|
||||
ifneq ($(wildcard /etc/bash_completion.d/.),)
|
||||
CPLDIR ?= /etc/bash_completion.d
|
||||
else
|
||||
ifneq ($(shell command -v pkg-config 2> /dev/null))
|
||||
CPLDIR ?= $$(pkg-config --variable=completionsdir bash-completion)
|
||||
CPLDIR ?= /etc/bash_completion.d
|
||||
endif
|
||||
|
||||
HAS_BREW := $(shell command -v brew 2> /dev/null)
|
||||
ifdef HAS_BREW
|
||||
CPLDIR ?= $$(brew --prefix)/etc/bash_completion.d
|
||||
endif
|
||||
|
||||
HAS_PKGCONFIG := $(shell command -v pkg-config 2> /dev/null)
|
||||
ifdef HAS_PKGCONFIG
|
||||
CPLDIR ?= $(shell pkg-config --variable=completionsdir bash-completion 2> /dev/null)
|
||||
endif
|
||||
|
||||
install:
|
||||
@echo Installing the executable to $(BINDIR)
|
||||
@mkdir -p $(BINDIR)
|
||||
@cp -f burrow $(BINDIR)/burrow
|
||||
@chmod 755 $(BINDIR)/burrow
|
||||
@install -m 755 burrow $(BINDIR)
|
||||
@echo Installing the manual page to $(MANDIR)/man1
|
||||
@mkdir -p $(MANDIR)
|
||||
@cp -f burrow.1 $(MANDIR)/man1/burrow.1
|
||||
@chmod 644 $(MANDIR)/man1/burrow.1
|
||||
@install -m 644 burrow.1 $(MANDIR)
|
||||
ifdef CPLDIR
|
||||
ifneq ($(CPLDIR),)
|
||||
@echo Installing the command completion to $(CPLDIR)
|
||||
@cp -f burrow.d $(CPLDIR)/burrow
|
||||
@chmod 644 $(CPLDIR)/burrow
|
||||
@mkdir -p $(CPLDIR)
|
||||
@install -m 644 burrow.d $(CPLDIR)/burrow
|
||||
endif
|
||||
endif
|
||||
|
||||
uninstall:
|
||||
@echo Removing the executable from $(BINDIR)
|
||||
@rm -f $(BINDIR)/burrow
|
||||
@echo Removing the manual page from $(MANDIR)/man1
|
||||
@rm -f $(BINDIR)/man1/burrow.1
|
||||
ifdef CPLDIR
|
||||
ifneq ($(CPLDIR),)
|
||||
@echo Removing the command completion from $(CPLDIR)
|
||||
@rm -f $(CPLDIR)/burrow
|
||||
endif
|
||||
endif
|
||||
|
||||
.PHONY: install uninstall
|
||||
|
|
105
README.md
105
README.md
|
@ -1,51 +1,63 @@
|
|||
# burrow ![status](https://img.shields.io/badge/status-working-green.svg?style=flat-square) ![license](https://img.shields.io/badge/license-GPL3-blue.svg?style=flat-square) ![bash](https://img.shields.io/badge/Bash-4%2B-lightgrey.svg?style=flat-square)
|
||||
# burrow ![status](https://travis-ci.com/jamestomasino/burrow.svg?branch=master) ![license](https://img.shields.io/badge/license-GPL3-blue.svg?style=flat-square)
|
||||
|
||||
**burrow** is a helper for building and managing a gopher hole.
|
||||
|
||||
## Installation
|
||||
|
||||
### Requirements
|
||||
* bash 4+ (OSX: `brew install bash`)
|
||||
* GNU sed (OSX: `brew install gnu-sed --with-default-names`)
|
||||
* GNU getopt (OSX: `brew install gnu-getopt --with-default-names`)
|
||||
|
||||
### Install
|
||||
|
||||
`sudo make install`
|
||||
|
||||
_Note: On systems without admin access the binary can be run directly from the
|
||||
git repo, but will lack `man` support and command completion._
|
||||
|
||||
See the [Getting Started](https://github.com/jamestomasino/burrow/wiki/Getting-Started) guide.
|
||||
|
||||
### Install on Linux / MacOS
|
||||
|
||||
`sudo make install`
|
||||
|
||||
### Install on BSD systems
|
||||
|
||||
#### FreeBSD
|
||||
|
||||
- Installing bash-completion via either `pkg install bash-completion` or via the `shells/bash-completion` port.
|
||||
- Installing the GNU version of make via either `pkg install gmake` or the `port devel/gmake`.
|
||||
- Rather than using `sudo make install`, run `sudo gmake install`.
|
||||
|
||||
#### OpenBSD
|
||||
|
||||
- Install the GNU version of make via either `pkg_add gmake` or the port `devel/gmake`.
|
||||
- There is no bash-completion package or port in OpenBSD. However the source code can be found at https://github.com/scop/bash-completion
|
||||
- Burrow appears to install and run without the presence of bash-completion. Exercise caution.
|
||||
- As root (or via `doas`), run `gmake install`.
|
||||
|
||||
|
||||
### Uninstall
|
||||
|
||||
`sudo make uninstall`
|
||||
`sudo make uninstall` # or gmake uninstall on BSD
|
||||
|
||||
## Usage
|
||||
|
||||
```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 create-config # generate a default config file
|
||||
burrow gophermap # edit a gophermap
|
||||
burrow rss # generate a RSS feed of phlog entries
|
||||
burrow edit-config # open your config file for editing
|
||||
burrow update-git # pull latest git repo for gopher dir, if exists
|
||||
```
|
||||
|
||||
- `phlog` will prompt for the title of the 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.
|
||||
- `edit-config` will open your burrow configuration file for easy editing.
|
||||
|
||||
- `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.
|
||||
- `phlog` will prompt for the title of a new post, then open it in your default
|
||||
`$EDITOR`.
|
||||
|
||||
- `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.
|
||||
- `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.
|
||||
|
||||
- `create-config` gives you the same settings as you have by default without
|
||||
a configuration file, but it provides you a starting point for customization.
|
||||
- `rss` will 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`.
|
||||
|
||||
- `update-git` is appropriate for cron jobs to keep the gopher hole in sync.
|
||||
- `update-git` will silently attempt to update a git repository at the location
|
||||
of your gopher hole. It is appropriate for use by a cron job.
|
||||
|
||||
_`man burrow` or `burrow -h` for more information._
|
||||
|
||||
|
@ -53,9 +65,11 @@ _`man burrow` or `burrow -h` for more information._
|
|||
|
||||
The following locations are available for configuration:
|
||||
|
||||
1) `$HOME/.config/burrow/config`
|
||||
2) `$HOME/.config/burrow`
|
||||
3) `$HOME/.burrow`
|
||||
1) `/etc/burrow/config`
|
||||
2) `$XDG_CONFIG_HOME`
|
||||
3) `$HOME/.config/burrow/config`
|
||||
4) `$HOME/.config/burrow`
|
||||
5) `$HOME/.burrow`
|
||||
|
||||
These files are processed in the order listed. Variables defined in multiple
|
||||
locations will use the last assigned value.
|
||||
|
@ -64,20 +78,41 @@ The following options are available (defaults shown):
|
|||
|
||||
```bash
|
||||
config_dir_gopher="$HOME/gopher" # local path to gopher site
|
||||
config_dir_phlog="phlog" # relative path to phlog
|
||||
config_dir_recipebox="recipebox" # relative path to recipe box
|
||||
config_dir_topics="topics" # relative path to topics directory
|
||||
config_gopher_server="sdf.org" # server of gopher host
|
||||
config_gopher_port="70" # port of gopher host
|
||||
config_gopher_root="/users/username/" # absolute path on gopher host to gopher site
|
||||
config_gopher_root="/users/username/" # path on gopher host to gopher site
|
||||
|
||||
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_git_commit=false # automatically commit changes if git repo
|
||||
config_git_push=false # automatically push changes if git repo
|
||||
config_autoindent=true # automatically reformat gophermaps with leading spaces
|
||||
# and parse links at the end of file
|
||||
|
||||
config_autoindent=true # automatically reformat gophermaps with leading "i"
|
||||
# types and parse links at the end of file
|
||||
|
||||
config_file_rss="rss.xml" # filename of RSS feed
|
||||
config_gopher_name="My Gopher Hole" # used in RSS feed output
|
||||
config_gopher_desc="Description" # used in RSS feed output
|
||||
config_rss_num_entries="10" # number of entries to inclued in RSS feed
|
||||
config_phlog_autorss=false # automatically generate RSS feed
|
||||
|
||||
```
|
||||
|
||||
_Note: This file is a valid Bash script and will be sourced upon load._
|
||||
|
||||
## Disambiguity
|
||||
|
||||
There is [another burrow project](https://github.com/sloumdrone/burrow) created
|
||||
by _sloumdrone_. His burrow project is a GUI gopher client. Please check it out!
|
||||
|
||||
There is also another project called "Burrow the Burrows" which can be found on gopher at: `gopher://kalos.mine.nu/1/burrow/index.gph`. It aims to construct and maintain a graph of the whole Gopherspace.
|
||||
|
||||
There is another [static site generator for gopher](https://github.com/hyperrealgopher/burrow) written in Haskell by @hyperrealgopher. It has similar features to my burrow.
|
||||
|
||||
_Armen_ now has a [gemini & spartan server](https://gitlab.com/armen138/burrow) named burrow.
|
||||
|
||||
## Contributing
|
||||
Pull requests are welcome. For major changes, please open an issue first to
|
||||
discuss what you would like to change.
|
||||
|
|
842
burrow
842
burrow
|
@ -1,70 +1,105 @@
|
|||
#!/usr/bin/env bash
|
||||
#!/bin/sh
|
||||
|
||||
version="v1.2.1"
|
||||
|
||||
shopt -s extglob
|
||||
configfiles="$HOME/.config/burrow/config $HOME/.config/burrow $HOME/.burrow"
|
||||
editor=${EDITOR:-vi}
|
||||
version="v1.7.9"
|
||||
configsystem="/etc/burrow/config"
|
||||
if [ -n "$XDG_CONFIG_HOME" ]; then
|
||||
configfiles="${XDG_CONFIG_HOME}/burrow/config"
|
||||
else
|
||||
configfiles="$HOME/.config/burrow/config $HOME/.config/burrow $HOME/.burrow"
|
||||
fi
|
||||
|
||||
# vars from config
|
||||
config_dir_gopher="$HOME/gopher/"
|
||||
config_dir_recipebox="recipebox"
|
||||
config_dir_gopher="$HOME/public_gopher/"
|
||||
config_dir_phlog="phlog"
|
||||
config_dir_topics="topics"
|
||||
config_gopher_server="sdf.org"
|
||||
config_gopher_server="envs.net"
|
||||
config_gopher_port="70"
|
||||
config_gopher_root="/users/username/"
|
||||
config_gopher_root="/~$USER/"
|
||||
config_phlog_gophermap=true
|
||||
config_phlog_usedate=true
|
||||
config_git_commit=false
|
||||
config_git_push=false
|
||||
config_autoindent=true
|
||||
config_file_rss="rss.xml"
|
||||
config_gopher_name="$USER's gopherhole"
|
||||
config_gopher_desc="this is my gopherhole"
|
||||
config_rss_num_entries="10"
|
||||
config_phlog_autorss=false
|
||||
config_gophermap_omitserver=false
|
||||
config_gophernicus=true
|
||||
|
||||
# coreutils function wrappers
|
||||
stat_func () {
|
||||
return 0
|
||||
}
|
||||
|
||||
# vars from flags
|
||||
flag_debug=0
|
||||
flag_version=0
|
||||
flag_help=0
|
||||
flag_noautoindent=0
|
||||
|
||||
# vars from args
|
||||
arg_options=hvd
|
||||
arg_longoptions=help,version,debug,noautoindent
|
||||
arg_options="hvd"
|
||||
arg_shortlist=0
|
||||
arg_recipe=0
|
||||
arg_gopherdir=0
|
||||
arg_phlog=0
|
||||
arg_topic=0
|
||||
arg_create_config=0
|
||||
arg_quickstart=0
|
||||
arg_edit_config=0
|
||||
arg_update_git=0
|
||||
arg_rss=0
|
||||
arg_gophermap=""
|
||||
|
||||
# silence directory movements
|
||||
pushd () {
|
||||
command pushd "$@" 2>/dev/null 1>&2
|
||||
push_d () {
|
||||
cd "$@" > /dev/null 2> /dev/null || exit
|
||||
}
|
||||
|
||||
popd () {
|
||||
command popd 2>/dev/null 1>&2
|
||||
pop_d () {
|
||||
cd - > /dev/null 2> /dev/null || exit
|
||||
}
|
||||
|
||||
function show_help() {
|
||||
cat > /dev/stdout << END
|
||||
show_help () {
|
||||
cat << END
|
||||
burrow [options] [commands]
|
||||
|
||||
COMMANDS:
|
||||
phlog Create new phlog entry
|
||||
recipe Add new recipe to box
|
||||
topic Add or update a topic
|
||||
create-config Create a default configuration file
|
||||
gophermap Edit a gophermap
|
||||
rss Generate an rss feed of recent phlog entries
|
||||
quickstart Create a new configuration file from prompts
|
||||
edit-config Edit your configuration file
|
||||
update-git Silently pulls gopher git repo if it exists
|
||||
|
||||
OPTIONAL FLAGS:
|
||||
-h, --help Show this help
|
||||
-v, --version Show current version info
|
||||
-d, --debug Debug mode
|
||||
-h Show this help
|
||||
-v Show current version info
|
||||
-d Debug mode
|
||||
|
||||
END
|
||||
}
|
||||
|
||||
function parse_input() {
|
||||
parsed=$(getopt --options=$arg_options --longoptions=$arg_longoptions --name "$0" -- "$@")
|
||||
if [[ $? -ne 0 ]]; then
|
||||
check_coreutils () {
|
||||
if stat -c"%U" /dev/null >/dev/null 2>/dev/null ; then
|
||||
# GNU environment
|
||||
stat_func () {
|
||||
stat -c %Y "$1"
|
||||
}
|
||||
date_func () {
|
||||
date -d "$1" +"%a, %d %b %Y %T %z" 2>/dev/null
|
||||
}
|
||||
else
|
||||
# BSD environment
|
||||
stat_func () {
|
||||
stat -Lnqr "$1" | awk '{print $10}'
|
||||
}
|
||||
date_func () {
|
||||
# $1 will be in YYYYMMDD format
|
||||
printf "%s" "$1" | awk 'BEGIN {n = split("Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec",month)} { y=substr($0, 0, 4); m=substr($0,5,2); gsub ("^0*", "", m); d=substr($0,7,2); print d, month[m], y, "00:00:00 +0000"}' 2>/dev/null
|
||||
}
|
||||
fi
|
||||
}
|
||||
|
||||
parse_input () {
|
||||
if ! parsed=$(getopt $arg_options "$@"); then
|
||||
die "Invalid input" 2
|
||||
fi
|
||||
|
||||
|
@ -72,22 +107,18 @@ function parse_input() {
|
|||
|
||||
while true; do
|
||||
case "$1" in
|
||||
-h|--help)
|
||||
-h)
|
||||
flag_help=1
|
||||
shift
|
||||
;;
|
||||
-v|--version)
|
||||
-v)
|
||||
flag_version=1
|
||||
shift
|
||||
;;
|
||||
-d|--debug)
|
||||
-d)
|
||||
flag_debug=1
|
||||
shift
|
||||
;;
|
||||
--noautoindent)
|
||||
flag_noautoindent=1
|
||||
shift
|
||||
;;
|
||||
--)
|
||||
shift
|
||||
break
|
||||
|
@ -98,288 +129,645 @@ function parse_input() {
|
|||
esac
|
||||
done
|
||||
|
||||
for arg in "$@"
|
||||
while test $# -gt 0
|
||||
do
|
||||
argc=${arg,,}
|
||||
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 ;;
|
||||
"update-git") arg_update_git=1 ;;
|
||||
*) echo "Unknown command: $arg";;
|
||||
"quickstart")
|
||||
arg_quickstart=1
|
||||
;;
|
||||
"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
|
||||
}
|
||||
|
||||
function day_suffix() {
|
||||
day_suffix () {
|
||||
case $(date +%d) in
|
||||
01|1|21|31) echo "st";;
|
||||
02|2|22) echo "nd";;
|
||||
03|3|23) echo "rd";;
|
||||
*) echo "th";;
|
||||
01|1|21|31) printf "st";;
|
||||
02|2|22) printf "nd";;
|
||||
03|3|23) printf "rd";;
|
||||
*) printf "th";;
|
||||
esac
|
||||
}
|
||||
|
||||
function update_gopher_date() {
|
||||
echo "Updating gopher last modified date"
|
||||
sed -i "s/.*Last\ Updated:.*/ ==== Last Updated: $(date +"%B %d$(day_suffix), %Y") ====/" "${config_dir_gopher}/gophermap"
|
||||
}
|
||||
|
||||
function check_directory() {
|
||||
if [[ ! -d "$1" ]]
|
||||
then
|
||||
die "Missing directory: $1 aborting."
|
||||
update_gopher_root () {
|
||||
touch "${config_dir_gopher}gophermap"
|
||||
newdate=$(date +"%B %d$(day_suffix), %Y")
|
||||
newString=$(printf "i ==== Last Updated: %s ====\\t\\t%s\\t%s" \
|
||||
"$newdate" \
|
||||
"$config_gopher_server" \
|
||||
"$config_gopher_port")
|
||||
if [ "$(uname)" = "Darwin" ]; then
|
||||
sed -i '' "s|.*Last\\ Updated:.*|${newString}|" "${config_dir_gopher}gophermap"
|
||||
else
|
||||
sed -i'' "s|.*Last\\ Updated:.*|${newString}|" "${config_dir_gopher}gophermap"
|
||||
fi
|
||||
}
|
||||
|
||||
function die {
|
||||
if [[ ! -z "$1" ]]; then
|
||||
echo "$1";
|
||||
if [[ "$2" =~ /^[0-9]+$/ ]] ; then
|
||||
exit "$2"
|
||||
check_directory () {
|
||||
if [ ! -d "$1" ]; then
|
||||
die "Missing directory: $1 aborting." 1
|
||||
fi
|
||||
}
|
||||
|
||||
die () {
|
||||
msg="$1"
|
||||
code="$2"
|
||||
|
||||
# exit code defaults to 1
|
||||
if printf "%s" "$code" | grep -q '^[0-9]+$'; then
|
||||
code=1
|
||||
fi
|
||||
|
||||
# output message to stdout or stderr based on code
|
||||
if [ -n "$msg" ]; then
|
||||
if [ "$code" -eq 0 ]; then
|
||||
printf "%s\\n" "$msg"
|
||||
else
|
||||
exit 1
|
||||
printf "%s\\n" "$msg" >&2
|
||||
fi
|
||||
fi
|
||||
exit "$code"
|
||||
}
|
||||
|
||||
function finish {
|
||||
if [[ -f "$temp_gophermap" ]]; then
|
||||
finish () {
|
||||
if [ -f "$temp_gophermap" ]; then
|
||||
rm "$temp_gophermap"
|
||||
fi
|
||||
if [[ -f "$temp_links" ]]; then
|
||||
rm "$temp_links"
|
||||
if [ -f "$temp_post" ]; then
|
||||
rm "$temp_post"
|
||||
fi
|
||||
}
|
||||
trap finish EXIT
|
||||
|
||||
function make_post() {
|
||||
query="$1"
|
||||
type="$2"
|
||||
use_gophermap="$3"
|
||||
use_date="$4"
|
||||
update_root="$5"
|
||||
make_post_git () {
|
||||
if $config_git_commit; then
|
||||
push_d "$config_dir_gopher"
|
||||
git add "${post_dir}/gophermap" "${post_file}" "$type_gophermap"
|
||||
if $update_root; then
|
||||
git add "${config_dir_gopher}/gophermap"
|
||||
fi
|
||||
if $config_phlog_autorss; then
|
||||
git add "${config_dir_gopher}${config_file_rss}"
|
||||
fi
|
||||
git commit -m "$post_type: $title"
|
||||
if $config_git_push; then
|
||||
git pull
|
||||
git push
|
||||
fi
|
||||
pop_d
|
||||
fi
|
||||
}
|
||||
|
||||
check_directory "$config_dir_gopher"
|
||||
check_directory "${config_dir_gopher}${type}"
|
||||
make_post_process_formatting () {
|
||||
# If using gophermap, prefix all post lines with "i" except links
|
||||
if $use_gophermap; then
|
||||
if $config_autoindent; then
|
||||
temp_post=$(mktemp -t "$(basename "$0").post.XXXXXXX") || \
|
||||
die "Failed to create temporary file" 1
|
||||
if $config_gophernicus; then
|
||||
awk -v server="${config_gopher_server}" -v port="${config_gopher_port}" '/(^[0-9cdghisGIT;\+].*\t|^[=\*\%\#\!\:\~\.].*)/ {print $0; next} {print "i" $0 "\t\t" server "\t" port}' "$post_file" > "${temp_post}"
|
||||
else
|
||||
awk -v server="${config_gopher_server}" -v port="${config_gopher_port}" '/^[0-9cdghisGIT;\+].*\t/ {print $0; next} {print "i" $0 "\t\t" server "\t" port}' "$post_file" > "${temp_post}"
|
||||
fi
|
||||
# create post file normally to respect umask
|
||||
touch "${post_file}"
|
||||
cat "${temp_post}" > "${post_file}"
|
||||
rm "${temp_post}"
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
read -r -e -p "$query" title
|
||||
if [[ $title == "" ]]
|
||||
then
|
||||
die "Cancelled." 0
|
||||
make_post_gophermap () {
|
||||
# Create temporary gophermap for new post
|
||||
temp_gophermap=$(mktemp -t "$(basename "$0").gophermap.XXXXXXX") || \
|
||||
die "Failed to create temporary file" 1
|
||||
|
||||
# Add appropriate link into temp gophermap
|
||||
if $use_gophermap; then
|
||||
if $use_date; then
|
||||
if $config_gophermap_omitserver; then
|
||||
# if using gophermap and date, no server
|
||||
printf "1%s - %s\\t%s\\n" \
|
||||
"$(date +%Y-%m-%d)" \
|
||||
"$title" \
|
||||
"$post_file_path" > "$temp_gophermap"
|
||||
else
|
||||
# if using gophermap and date
|
||||
printf "1%s - %s\\t%s\\t%s\\t%s\\n" \
|
||||
"$(date +%Y-%m-%d)" \
|
||||
"$title" \
|
||||
"$post_file_path" \
|
||||
"$config_gopher_server" \
|
||||
"$config_gopher_port" > "$temp_gophermap"
|
||||
fi
|
||||
else
|
||||
if $config_gophermap_omitserver; then
|
||||
# if using gophermap but not date, no server
|
||||
printf "1%s\\t%s\\n" \
|
||||
"$title" \
|
||||
"$post_file_path" > "$temp_gophermap"
|
||||
else
|
||||
# if using gophermap but not date
|
||||
printf "1%s\\t%s\\t%s\\t%s\\n" \
|
||||
"$title" \
|
||||
"$post_file_path" \
|
||||
"$config_gopher_server" \
|
||||
"$config_gopher_port" > "$temp_gophermap"
|
||||
fi
|
||||
fi
|
||||
else
|
||||
if $use_date; then
|
||||
if $config_gophermap_omitserver; then
|
||||
# if not using gophermap but using date, no server
|
||||
printf "0%s - %s\\t%s\\n" \
|
||||
"$(date +%Y-%m-%d)" \
|
||||
"$title" \
|
||||
"$post_file_path" > "$temp_gophermap"
|
||||
else
|
||||
# if not using gophermap but using date
|
||||
printf "0%s - %s\\t%s\\t%s\\t%s\\n" \
|
||||
"$(date +%Y-%m-%d)" \
|
||||
"$title" \
|
||||
"$post_file_path" \
|
||||
"$config_gopher_server" \
|
||||
"$config_gopher_port" > "$temp_gophermap"
|
||||
fi
|
||||
else
|
||||
if $config_gophermap_omitserver; then
|
||||
# if not using gophermap or date, no server
|
||||
printf "0%s\\t%s\\n" \
|
||||
"$title" \
|
||||
"$post_file_path" > "$temp_gophermap"
|
||||
else
|
||||
# if not using gophermap or date
|
||||
printf "0%s\\t%s\\t%s\\t%s\\n" \
|
||||
"$title" \
|
||||
"$post_file_path" \
|
||||
"$config_gopher_server" \
|
||||
"$config_gopher_port" > "$temp_gophermap"
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
|
||||
type_gophermap="${config_dir_gopher}${type}/gophermap"
|
||||
if [ -f "$type_gophermap" ]; then
|
||||
cat "$type_gophermap" >> "$temp_gophermap"
|
||||
fi
|
||||
|
||||
if ! $use_date; then
|
||||
sort -fk 1.2 "$temp_gophermap" -o "$temp_gophermap"
|
||||
fi
|
||||
touch "$type_gophermap"
|
||||
cat "$temp_gophermap" > "$type_gophermap"
|
||||
rm "$temp_gophermap"
|
||||
|
||||
# Sort gophermap alphabetically if not using date
|
||||
if [ "$use_gophermap" ] && [ ! "$use_date" ]; then
|
||||
sort -fo "$type_gophermap" "$type_gophermap"
|
||||
fi
|
||||
}
|
||||
|
||||
make_post_unprocess () {
|
||||
if [ $config_autoindent ]; then
|
||||
temp_post=$(mktemp -t "$(basename "$0").post.XXXXXXX") || \
|
||||
die "Failed to create temporary file" 1
|
||||
|
||||
# If using gophermaps, unformat it for editing
|
||||
if $use_gophermap; then
|
||||
awk -F"\\t" '/^[0-9h\+GIThs].*\t/ {print $0; next} {sub(/^i/, "", $1);print $1}' "$post_file" > "${temp_post}"
|
||||
else
|
||||
# copy existing post to tempfile
|
||||
cp "$post_file" "${temp_post}"
|
||||
fi
|
||||
|
||||
fi
|
||||
|
||||
# Get timestamp of tempfile
|
||||
temp_post_time=$(stat_func "$temp_post")
|
||||
|
||||
# Edit tempfile
|
||||
${EDITOR:-vim} "$temp_post"
|
||||
|
||||
# Verify that timestamp changed after editing, or abort
|
||||
temp_post_time_check=$(stat_func "$temp_post")
|
||||
if [ "$temp_post_time" -ne "$temp_post_time_check" ] ; then
|
||||
touch "${post_file}"
|
||||
cat "${temp_post}" > "${post_file}"
|
||||
rm "${temp_post}"
|
||||
else
|
||||
rm "${temp_post}"
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
make_post_temp () {
|
||||
# Create a tempfile to do our work
|
||||
temp_post=$(mktemp -t "$(basename "$0").post.XXXXXXX") || \
|
||||
die "Failed to create temporary file" 1
|
||||
|
||||
if [ -n "$title" ]; then
|
||||
{ printf "%s\\n%s\\n" "----------------------------------------" "$title"
|
||||
if $use_date; then
|
||||
date +"%B %d$(day_suffix), %Y"
|
||||
fi
|
||||
printf "%s\\n\\n\\n" "----------------------------------------"
|
||||
} > "$temp_post"
|
||||
else
|
||||
{ printf "%s\\n%s\\n" "----------------------------------------" "$post_type"
|
||||
printf "%s\\n\\n\\n" "----------------------------------------"
|
||||
} > "$temp_post"
|
||||
fi
|
||||
|
||||
# Check timestamp before editing file
|
||||
temp_post_time=$(stat_func "$temp_post")
|
||||
${EDITOR:-vim} "$temp_post"
|
||||
|
||||
# Verify that timestamp changed after editing, or abort
|
||||
temp_post_time_check=$(stat_func "$temp_post")
|
||||
|
||||
# If we saved a change, create the new file
|
||||
if [ "$temp_post_time" -ne "$temp_post_time_check" ] ; then
|
||||
mkdir -p "${post_dir}"
|
||||
touch "${post_file}"
|
||||
cat "${temp_post}" > "${post_file}"
|
||||
rm "${temp_post}"
|
||||
else
|
||||
rm "${temp_post}"
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
make_post_paths () {
|
||||
type_gophermap="${config_dir_gopher}${post_type}/gophermap"
|
||||
|
||||
if $use_gophermap; then
|
||||
title_slug=$(echo "${title}" | sed -E -e 's/[^[:alnum:]]/-/g' -e 's/^-+|-+$//g' | tr -s '-' | tr '[:upper:]' '[:lower:]')
|
||||
title_slug=$(printf "%s" "$title" | \
|
||||
sed -E -e 's/[^[:alnum:]]/-/g' -e 's/^-+|-+$//g' | tr -s '-' | tr '[:upper:]' '[:lower:]')
|
||||
if $use_date; then
|
||||
post_dir="${config_dir_gopher}${type}/$(date +%Y%m%d)-$title_slug"
|
||||
post_path="${config_gopher_root}${type}/$(date +%Y%m%d)-$title_slug"
|
||||
post_dir="${config_dir_gopher}${post_type}/$(date +%Y%m%d)-$title_slug"
|
||||
post_path="${config_gopher_root}${post_type}/$(date +%Y%m%d)-$title_slug"
|
||||
else
|
||||
post_dir="${config_dir_gopher}${type}/$title_slug"
|
||||
post_path="${config_gopher_root}${type}/$title_slug"
|
||||
if [ -z "$title_slug" ]; then
|
||||
post_dir="${config_dir_gopher}${post_type}"
|
||||
post_path="${config_gopher_root}${post_type}"
|
||||
else
|
||||
post_dir="${config_dir_gopher}${post_type}/$title_slug"
|
||||
post_path="${config_gopher_root}${post_type}/$title_slug"
|
||||
fi
|
||||
fi
|
||||
post_file="${post_dir}/gophermap"
|
||||
post_file_path="${post_path}"
|
||||
else
|
||||
post_dir="${config_dir_gopher}${type}"
|
||||
post_path="${config_gopher_root}${type}"
|
||||
title_slug=$(echo "${title}" | sed -E -e 's/[^[:alnum:]]/-/g' -e 's/^-+|-+$//g' | tr -s '-' | tr '[:upper:]' '[:lower:]')
|
||||
post_dir="${config_dir_gopher}${post_type}"
|
||||
post_path="${config_gopher_root}${post_type}"
|
||||
title_slug=$(printf "%s" "$title" | \
|
||||
sed -E -e 's/[^[:alnum:]]/-/g' -e 's/^-+|-+$//g' | tr -s '-' | tr '[:upper:]' '[:lower:]')
|
||||
if $use_date; then
|
||||
title_slug="$(date +%Y%m%d)-${title_slug}"
|
||||
fi
|
||||
post_file="${post_dir}/${title_slug}.txt"
|
||||
post_file_path="${post_path}/${title_slug}.txt"
|
||||
fi
|
||||
}
|
||||
|
||||
if [[ -f $post_file ]]
|
||||
then
|
||||
$editor "$post_file"
|
||||
make_post () {
|
||||
query="$1"
|
||||
post_type="$2"
|
||||
use_gophermap="$3"
|
||||
use_date="$4"
|
||||
update_root="$5"
|
||||
create_rss="$6"
|
||||
create_gophermap="$7"
|
||||
|
||||
check_directory "$config_dir_gopher"
|
||||
|
||||
if [ ! -d "${config_dir_gopher}${post_type}" ]; then
|
||||
mkdir -p "${config_dir_gopher}${post_type}"
|
||||
fi
|
||||
|
||||
if [ -n "$query" ]; then
|
||||
printf "%s" "$query"
|
||||
read -r title
|
||||
if [ -z "$title" ]; then
|
||||
die "Cancelled." 0
|
||||
fi
|
||||
else
|
||||
mkdir -p "${post_dir}"
|
||||
if [[ -f "${post_dir}/.template" ]]
|
||||
then
|
||||
cat "${post_dir}/.template" > "$post_file"
|
||||
title=""
|
||||
fi
|
||||
|
||||
make_post_paths
|
||||
|
||||
if [ -f "$post_file" ]; then
|
||||
make_post_unprocess
|
||||
if [ "$?" -eq 1 ]; then
|
||||
die "Aborted edit" 0
|
||||
fi
|
||||
make_post_process_formatting
|
||||
else
|
||||
make_post_temp
|
||||
if [ "$?" -eq 1 ]; then
|
||||
die "Aborted post" 0
|
||||
fi
|
||||
make_post_process_formatting
|
||||
if $create_gophermap; then
|
||||
make_post_gophermap
|
||||
fi
|
||||
fi
|
||||
|
||||
if $update_root; then
|
||||
update_gopher_root
|
||||
fi
|
||||
|
||||
if $create_rss; then
|
||||
make_rss
|
||||
fi
|
||||
|
||||
make_post_git
|
||||
}
|
||||
|
||||
make_rss () {
|
||||
push_d "${config_dir_gopher}${config_dir_phlog}"
|
||||
search_list=$(find . \
|
||||
-mindepth 1 \
|
||||
-type f \
|
||||
-print | \
|
||||
grep -v "^\\./gophermap$" |
|
||||
sort -r | \
|
||||
head -n "${config_rss_num_entries}")
|
||||
|
||||
{
|
||||
printf '<?xml version="1.0"?><rss version="2.0"><channel>'
|
||||
printf "\\n<title>%s</title>\\n" "$config_gopher_name"
|
||||
printf "<link>gopher://%s%s</link>\\n" "$config_gopher_server" "$config_gopher_root"
|
||||
printf "<description>%s</description>\\n" "$config_gopher_desc"
|
||||
} > "${config_dir_gopher}${config_file_rss}"
|
||||
|
||||
for f in $search_list; do
|
||||
filename="$(printf "%s" "$f" | sed "s|${config_dir_gopher}${config_dir_phlog}/||" | sed "s|^\\./||")"
|
||||
if printf "%s" "$filename" | grep -q "/gophermap"; then
|
||||
item_type=1
|
||||
filename="$( printf "%s" "$filename" | sed "s|gophermap$||")"
|
||||
else
|
||||
echo "Creating $post_file"
|
||||
item_type=0
|
||||
fi
|
||||
date="$(printf "%s" "$filename" | sed 's|^\./||' | awk 'BEGIN { FS="-" } { print $1; }')"
|
||||
title="$(printf "%s" "$filename" | awk 'BEGIN { FS="-" } { $1=""; print $0; }' | sed "s|/gophermap||" | sed 's/^\ //' | sed 's|/$||' | awk '{for(i=1;i<=NF;i++){ $i=toupper(substr($i,1,1)) substr($i,2) }}1')"
|
||||
dateval=$(date_func "$date")
|
||||
if [ -n "$dateval" ]; then
|
||||
{
|
||||
echo "----------------------------------------"
|
||||
echo "$title"
|
||||
if $use_date; then
|
||||
date +"%B %d$(day_suffix), %Y"
|
||||
printf "<item>\\n"
|
||||
printf " <title>%s</title>\\n" "$title"
|
||||
printf " <link>gopher://%s/%s%s%s/%s</link>\\n" "$config_gopher_server" "$item_type" "$config_gopher_root" "$config_dir_phlog" "$filename"
|
||||
printf " <pubdate>%s</pubdate>\\n" "$dateval"
|
||||
printf " <description><![CDATA[<pre>\\n"
|
||||
if [ "$item_type" -eq 1 ]
|
||||
then
|
||||
awk -v server="${config_gopher_server}" -v port="${config_gopher_port}" -F"\\t" '/^[2-9\+GITs].*\t/ {print $0; next} /^h.*\t/ { l=substr($1, 2, length($1)); print l "\n " substr($2, 5, length($2)); next } /^[0-1].*\t/ { l=substr($1, 2, length($1)); t=substr($1,1,1); (!$3) ? s=server : s=$3; print l "\n gopher://" s "/" t $2; next } {sub(/^i/, "", $1);print $1}' "$f"
|
||||
else
|
||||
cat "$f"
|
||||
fi
|
||||
echo "----------------------------------------"
|
||||
echo ""
|
||||
echo ""
|
||||
if $use_gophermap; then
|
||||
echo "Links:"
|
||||
echo ""
|
||||
fi
|
||||
} >> "$post_file"
|
||||
printf "</pre>]]></description>\\n"
|
||||
printf "</item>\\n"
|
||||
} >> "${config_dir_gopher}${config_file_rss}"
|
||||
fi
|
||||
done
|
||||
pop_d
|
||||
printf "</channel>\\n" >> "${config_dir_gopher}${config_file_rss}"
|
||||
printf "</rss>\\n" >> "${config_dir_gopher}${config_file_rss}"
|
||||
}
|
||||
|
||||
$editor "$post_file"
|
||||
|
||||
if $use_gophermap; then
|
||||
if [[ $config_autoindent == true ]] && [[ $flag_noautoindent == 0 ]]
|
||||
then
|
||||
echo "Processing for links and autoindenting"
|
||||
temp_links=$(mktemp -t "$(basename "$0").links.XXXXXXX") || die "Failed to create temporary file" 1
|
||||
sed -n '/^Links:$/,$p' "$post_file" | tail -n +2 > "$temp_links"
|
||||
sed -i '/^Links:$/,$d' "$post_file"
|
||||
sed -i 's/^/ /' "$post_file"
|
||||
cat "$temp_links" >> "$post_file"
|
||||
rm "$temp_links"
|
||||
fi
|
||||
edit_config () {
|
||||
for configfile in $configfiles; do
|
||||
if [ -f "$configfile" ] && [ -w "$configfile" ]; then
|
||||
${EDITOR:-vim} "$configfile"
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
echo "Updating $type"
|
||||
temp_gophermap=$(mktemp -t "$(basename "$0").gophermap.XXXXXXX") || die "Failed to create temporary file" 1
|
||||
yesno () {
|
||||
printf "%s " "$1"
|
||||
read -r yn
|
||||
case $yn in
|
||||
[Yy]* ) result=0 ;;
|
||||
* ) result=1 ;;
|
||||
esac
|
||||
return $result
|
||||
}
|
||||
|
||||
if $use_gophermap; then
|
||||
if $use_date; then
|
||||
# if using gophermap and date
|
||||
echo -e "1$(date +%Y-%m-%d) - $title\t${post_file_path}\t${config_gopher_server}\t${config_gopher_port}" > "$temp_gophermap"
|
||||
else
|
||||
# if using gophermap but not date
|
||||
echo -e "1$title\t${post_file_path}\t${config_gopher_server}\t${config_gopher_port}" > "$temp_gophermap"
|
||||
fi
|
||||
quickstart () {
|
||||
printf "Location of your local gopher directory? "
|
||||
read -r config_dir_gopher
|
||||
# add trailing slash if missing
|
||||
config_dir_gopher="${config_dir_gopher%/}/"
|
||||
printf "Hostname of your gopher server? "
|
||||
read -r config_gopher_server
|
||||
printf "Port of your gopher server? "
|
||||
read -r config_gopher_port
|
||||
printf "Root directory of your gopher site? "
|
||||
read -r config_gopher_root
|
||||
if yesno "Is your gopher server 'gophernicus'? "; then
|
||||
config_gophernicus=true
|
||||
else
|
||||
config_gophernicus=false
|
||||
fi
|
||||
# add trailing slash if missing
|
||||
config_gopher_root="${config_gopher_root%/}/"
|
||||
if yesno "Create a phlog? "; then
|
||||
printf "Phlog directory? (relative to root of gopher site) "
|
||||
read -r config_dir_phlog
|
||||
# remove leading slash if present
|
||||
config_dir_phlog="${config_dir_phlog#/}"
|
||||
if yesno "Include gophermap? "; then
|
||||
config_phlog_gophermap=true
|
||||
else
|
||||
if $use_date; then
|
||||
# if not using gophermap but using date
|
||||
echo -e "0$(date +%Y-%m-%d) - $title\t${post_file_path}\t${config_gopher_server}\t${config_gopher_port}" > "$temp_gophermap"
|
||||
else
|
||||
# if not using gophermap or date
|
||||
echo -e "0$title\t${post_file_path}\t${config_gopher_server}\t${config_gopher_port}" > "$temp_gophermap"
|
||||
fi
|
||||
config_phlog_gophermap=false
|
||||
fi
|
||||
|
||||
cat "$type_gophermap" >> "$temp_gophermap"
|
||||
cat "$temp_gophermap" > "$type_gophermap"
|
||||
rm "$temp_gophermap"
|
||||
|
||||
# sort gophermap if not using date
|
||||
if ! $use_date; then
|
||||
sort -fo "${post_dir}/gophermap" "${post_dir}/gophermap"
|
||||
if yesno "Include the date in your phlog posts? "; then
|
||||
config_phlog_usedate=true
|
||||
else
|
||||
config_phlog_usedate=false
|
||||
fi
|
||||
|
||||
if $update_root; then
|
||||
update_gopher_date
|
||||
if yesno "Auto-commit to git repo? "; then
|
||||
config_git_commit=true
|
||||
else
|
||||
config_git_commit=false
|
||||
fi
|
||||
|
||||
if [[ $config_git_commit != false ]]
|
||||
then
|
||||
echo "Committing to git repository"
|
||||
pushd "$config_dir_gopher"
|
||||
git add "${post_dir}/gophermap" "${post_file}"
|
||||
if $update_root; then
|
||||
git add "${config_dir_gopher}/gophermap"
|
||||
fi
|
||||
git commit -m "$type: $title"
|
||||
if [[ $config_git_push != false ]]
|
||||
then
|
||||
echo "Pushing to git remote"
|
||||
git pull
|
||||
git push
|
||||
fi
|
||||
popd
|
||||
if yesno "Auto-push to git remote? "; then
|
||||
config_git_push=true
|
||||
else
|
||||
config_git_push=false
|
||||
fi
|
||||
if yesno "Auto-indent posts? "; then
|
||||
config_autoindent=true
|
||||
else
|
||||
config_autoindent=false
|
||||
fi
|
||||
if yesno "Auto-generate phlog RSS? "; then
|
||||
config_phlog_autorss=true
|
||||
printf "Name of gopher hole? "
|
||||
read -r config_gopher_name
|
||||
printf "Description of gopher hole? "
|
||||
read -r config_gopher_desc
|
||||
printf "RSS filename? "
|
||||
read -r config_file_rss
|
||||
printf "Number of RSS entries? "
|
||||
read -r config_rss_num_entries
|
||||
else
|
||||
config_phlog_autorss=false
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
function create_config() {
|
||||
if [[ ! -f "$HOME/.config/burrow/config" ]] &&
|
||||
[[ ! -f "$HOME/.config/burrow" ]] &&
|
||||
[[ ! -f "$HOME/.burrow" ]]
|
||||
then
|
||||
config="$HOME/.config/burrow/config"
|
||||
create_config () {
|
||||
match=0
|
||||
for configfile in $configfiles; do
|
||||
if [ -f "$configfile" ]; then
|
||||
match=1
|
||||
fi
|
||||
done
|
||||
if [ $match -eq 0 ]; then
|
||||
if [ -n "$XDG_CONFIG_HOME" ]; then
|
||||
config="$XDG_CONFIG_HOME/burrow/config"
|
||||
else
|
||||
config="$HOME/.config/burrow/config"
|
||||
fi
|
||||
mkdir -p "$(dirname "$config")"
|
||||
{
|
||||
echo "config_dir_gopher=\"$HOME/gopher/\""
|
||||
echo "config_dir_phlog=\"phlog\""
|
||||
echo "config_dir_recipebox=\"recipebox\""
|
||||
echo "config_dir_topics=\"topics\""
|
||||
echo "config_gopher_server=\"sdf.org\""
|
||||
echo "config_gopher_port=\"70\""
|
||||
echo "config_gopher_root=\"/users/username/\""
|
||||
echo "config_git_commit=false"
|
||||
echo "config_git_push=false"
|
||||
echo "config_autoindent=true"
|
||||
printf "config_dir_gopher=\"%s\"\\n" "$config_dir_gopher"
|
||||
printf "\\n"
|
||||
printf "config_gopher_server=\"%s\"\\n" "$config_gopher_server"
|
||||
printf "config_gopher_port=\"%s\"\\n" "$config_gopher_port"
|
||||
printf "config_gopher_root=\"%s\"\\n" "$config_gopher_root"
|
||||
printf "\\n"
|
||||
printf "config_dir_phlog=\"%s\"\\n" "$config_dir_phlog"
|
||||
printf "config_phlog_gophermap=%s\\n" "$config_phlog_gophermap"
|
||||
printf "config_phlog_usedate=%s\\n" "$config_phlog_usedate"
|
||||
printf "config_phlog_autorss=%s\\n" "$config_phlog_autorss"
|
||||
printf "\\n"
|
||||
printf "config_git_commit=%s\\n" "$config_git_commit"
|
||||
printf "config_git_push=%s\\n" "$config_git_push"
|
||||
printf "\\n"
|
||||
printf "config_autoindent=%s\\n" "$config_autoindent"
|
||||
printf "config_gophernicus=%s\\n" "$config_gophernicus"
|
||||
printf "\\n"
|
||||
printf "config_file_rss=\"%s\"\\n" "$config_file_rss"
|
||||
printf "config_gopher_name=\"%s\"\\n" "$config_gopher_name"
|
||||
printf "config_gopher_desc=\"%s\"\\n" "$config_gopher_desc"
|
||||
printf "config_rss_num_entries=\"%s\"\\n" "$config_rss_num_entries"
|
||||
} >> "$config"
|
||||
else
|
||||
echo "Configuration already exists. Abort."
|
||||
fi
|
||||
}
|
||||
|
||||
function update_git() {
|
||||
pushd "$config_dir_gopher"
|
||||
if [[ $? -eq 0 ]]
|
||||
then
|
||||
if [[ $(git rev-parse --is-inside-work-tree 2> /dev/null) ]]
|
||||
then
|
||||
git pull -q
|
||||
fi
|
||||
popd
|
||||
update_git () {
|
||||
push_d "$config_dir_gopher"
|
||||
if [ "$(git rev-parse --is-inside-work-tree 2> /dev/null)" ]; then
|
||||
git pull -q > /dev/null 2> /dev/null
|
||||
fi
|
||||
pop_d
|
||||
}
|
||||
|
||||
function main() {
|
||||
main () {
|
||||
check_coreutils "$@"
|
||||
parse_input "$@"
|
||||
|
||||
if [[ $arg_shortlist -gt 0 ]]
|
||||
then
|
||||
die "phlog topic recipe create-config update-git -v -h -d --version --help --debug --noautoindent" 0
|
||||
if [ $arg_shortlist -gt 0 ]; then
|
||||
out="phlog gophermap rss edit-config update-git"
|
||||
die "${out}" 0
|
||||
fi
|
||||
|
||||
if [[ $flag_version -gt 0 ]]
|
||||
then
|
||||
echo "$version"
|
||||
if [ $flag_version -gt 0 ]; then
|
||||
printf "%s\\n" "$version"
|
||||
fi
|
||||
|
||||
if [[ $flag_help -gt 0 ]]
|
||||
then
|
||||
if [ $flag_help -gt 0 ]; then
|
||||
show_help
|
||||
fi
|
||||
|
||||
if [[ $flag_debug -gt 0 ]]
|
||||
then
|
||||
if [ $flag_debug -gt 0 ]; then
|
||||
set -x
|
||||
fi
|
||||
|
||||
if [[ $arg_create_config -gt 0 ]]
|
||||
then
|
||||
if [ $arg_quickstart -gt 0 ]; then
|
||||
quickstart
|
||||
create_config
|
||||
fi
|
||||
|
||||
for configfile in $configfiles
|
||||
do
|
||||
if [[ -f $configfile ]]
|
||||
then
|
||||
source "$configfile"
|
||||
if [ $arg_edit_config -gt 0 ]; then
|
||||
create_config
|
||||
edit_config
|
||||
fi
|
||||
|
||||
# load system config first
|
||||
if [ -f "$configsystem" ]; then
|
||||
# shellcheck disable=SC1090
|
||||
. "$configsystem"
|
||||
fi
|
||||
|
||||
# load any user configuration files in order
|
||||
for configfile in $configfiles; do
|
||||
if [ -f "$configfile" ]; then
|
||||
# shellcheck disable=SC1090
|
||||
. "$configfile"
|
||||
fi
|
||||
done
|
||||
|
||||
if [[ ${arg_update_git} -gt 0 ]]
|
||||
then
|
||||
if [ $arg_gopherdir -gt 0 ]; then
|
||||
die "${config_dir_gopher}" 0
|
||||
fi
|
||||
|
||||
if [ $arg_update_git -gt 0 ]; then
|
||||
update_git
|
||||
fi
|
||||
|
||||
if [[ ${arg_recipe} -gt 0 ]]
|
||||
then
|
||||
make_post "What is the name of your recipe? " "$config_dir_recipebox" false false true
|
||||
if [ "$arg_gophermap" != "" ]; then
|
||||
make_post "" \
|
||||
"${arg_gophermap}" \
|
||||
true \
|
||||
false \
|
||||
true \
|
||||
false \
|
||||
false
|
||||
fi
|
||||
|
||||
if [[ ${arg_topic} -gt 0 ]]
|
||||
then
|
||||
make_post "What is the name of your topic? " "$config_dir_topics" true false true
|
||||
if [ $arg_phlog -gt 0 ]; then
|
||||
make_post "Enter a title for your post: " \
|
||||
"$config_dir_phlog" \
|
||||
"$config_phlog_gophermap" \
|
||||
"$config_phlog_usedate" \
|
||||
true \
|
||||
${config_phlog_autorss} \
|
||||
true
|
||||
fi
|
||||
|
||||
if [[ ${arg_phlog} -gt 0 ]]
|
||||
then
|
||||
make_post "Enter a title for your post: " "$config_dir_phlog" true true true
|
||||
if [ $arg_rss -gt 0 ]; then
|
||||
make_rss
|
||||
fi
|
||||
}
|
||||
|
||||
|
|
51
burrow.1
51
burrow.1
|
@ -1,4 +1,4 @@
|
|||
.TH BURROW 1 "03 Mar 2018" "version 1.2.0"
|
||||
.TH BURROW 1 "06 Mar 2020" "version 1.7.9"
|
||||
.SH NAME
|
||||
burrow \- a helper for building and managing a gopher hole
|
||||
.SH SYNOPSIS
|
||||
|
@ -9,43 +9,54 @@ modification, and maintenance of a gopher hole.
|
|||
.SH COMMANDS
|
||||
.TP
|
||||
.B phlog
|
||||
Create a new phlog entry.
|
||||
Prompt for the title of a new post, then open it in your default
|
||||
$EDITOR.
|
||||
.TP
|
||||
.B recipe
|
||||
Add or update a recipe to the recipe box.
|
||||
.B topic
|
||||
Add or update a topic in your topics directory.
|
||||
.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 create-config
|
||||
Generates a default configuration file at
|
||||
.I ~/.config/burrow/config
|
||||
if no other configuration file exists. It is populated with the default
|
||||
settings.
|
||||
.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 quickstart
|
||||
Creates a new configuration file from interactive user prompts.
|
||||
.TP
|
||||
.B edit-config
|
||||
Opens your burrow configuration file for editing if it exists.
|
||||
.TP
|
||||
.B update-git
|
||||
If the gopher directory resides within a git repository, this action will do a
|
||||
silent
|
||||
Silently attempt to update a git repository at the location
|
||||
of your gopher hole. It is appropriate for use by a cron job.
|
||||
.TP
|
||||
.B git-pull
|
||||
which is useful for crons.
|
||||
.SH OPTIONS
|
||||
.TP
|
||||
.B -v, --version
|
||||
.B -v
|
||||
Display current version information.
|
||||
.TP
|
||||
.B -d, --debug
|
||||
.B -d
|
||||
Debug mode.
|
||||
.TP
|
||||
.B -h, --help
|
||||
.TP
|
||||
.B -h
|
||||
Show the help.
|
||||
.SH FILES
|
||||
.I $XDG_CONFIG_HOME
|
||||
,
|
||||
.I ~/.config/burrow/config
|
||||
,
|
||||
,
|
||||
.I ~/.config/burrow
|
||||
,
|
||||
,
|
||||
.I ~/.burrow
|
||||
,
|
||||
.I /etc/burrow/config
|
||||
: configuration settings for burrow. If none of these are available, the default
|
||||
configuration is loaded.
|
||||
.SH BUGS
|
||||
None known.
|
||||
.SH AUTHOR
|
||||
James Tomasino <tomasino (at) sdf (dot) org>
|
||||
James Tomasino <tomasino (at) lavabit (dot) com>
|
||||
|
|
46
burrow.d
46
burrow.d
|
@ -1,22 +1,46 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
_burrow()
|
||||
{
|
||||
# Get basic autocomplete commands from the function itself
|
||||
local helplist
|
||||
helplist=$(burrow shortlist)
|
||||
|
||||
# Combine all the lists for autocomplete
|
||||
_burrow() {
|
||||
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
|
||||
partial_search_dir="${gopher_dir}${COMP_WORDS[2]}"
|
||||
if [ -d "$partial_search_dir" ]; then
|
||||
search_dir="$partial_search_dir"
|
||||
else
|
||||
partial_search_dir=$(dirname "$partial_search_dir")
|
||||
if [ -d "$partial_search_dir" ]; then
|
||||
search_dir="$partial_search_dir"
|
||||
fi
|
||||
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||" )
|
||||
local suggestions=( $( compgen -W "$gophermaps $directories" -- "$cur" ) )
|
||||
if [ "${#suggestions[@]}" == "1" ]; then
|
||||
local resp=$(echo ${suggestions[0]/%\ */})
|
||||
COMPREPLY=("$resp")
|
||||
else
|
||||
COMPREPLY=("${suggestions[@]}")
|
||||
fi
|
||||
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 +49,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
|
||||
|
|
Loading…
Reference in New Issue