Make some scripts properly extensible, add docs concerning note system, simplify upload/pastebin/screenshot scripts

This commit is contained in:
Daniel Flanagan 2019-10-21 11:12:42 -05:00
parent f48c3a36a5
commit 6e911f59e0
10 changed files with 140 additions and 23 deletions

View File

@ -112,4 +112,5 @@ Plug 'neoclide/coc-json' " coc config ft
Plug 'JakeBecker/elixir-ls', {'for': ['elixir', 'eelixir'], 'do': { -> g:elixirls.compile() }}
Plug 'tpope/vim-dadbod' " databasing in vim
Plug 'lytedev/elm-vim' " elm lang
Plug 'google/vim-jsonnet' " jsonnet
Plug 'ssh://git@git.lyte.dev:2222/lytedev/vim-lytlang.git'

102
doc/notes.md Normal file
View File

@ -0,0 +1,102 @@
# Notes
Like most people, I needed a way to keep decent notes on my machines. The way
that I prefer to take notes was writing text files with the option of grouping
together hierarchical data into nested bullet-style lists.
## Tools
Vim (or specifically Neovim) and Markdown for reading and writing have fit the
bill very well for me. Git has worked amazingly for syncing/merging. I setup
some bash aliases to allow me to do this without even thinking (or even
automatically!) and note-taking life has been good ever since.
On occasion, I do want actual spreadsheets. I tend to use [my fork of
`sc-im`][sc-im] and a handful of Lua scripts for it. Primarily these are finance
or D&D-related.
Full searchability of notes and spreadsheets is very important. Since my notes
manifest as files on a filesystem, grep (or specifically [ripgrep][rg]) is
incredible. When I need to find files by their filename, I tend to use find (or
specifically [`fd`][fd]).
Navigating between notes is also very important. For the most part, vim's `gf`
binding does the job. Barring that, [`fzf`] and good vim buffer management have
worked brilliantly for me.
It's nice when editing your notes feels clean and comfortable and when they just
*look good*. I really like the [`goyo` vim plugin by junegunn][goyo] to provide
some space at times. Here's a [link to a screenshot][goyo-screenshot].
My notes repository is on a private `Gitea` instance which automatically gets
mirrored to both GitHub and GitLab because redundancy is good and hooray for
distributed software! If I wanted, I could easily setup auto-sync (even just add
`nsync &` to the end of all the alises/scripts below would probably suffice),
but I find that most notes are not so urgent to sync and that I am sure to do so
if I need them. I should also probably encrypt/decrypt them on syncing.
I rarely ever make non-ephemeral notes on my phone and use Google Keep for those
notes. If they are more static, I would just copy and paste later at a machine
or if there is an emergency, I can absolutely edit my notes the same way I do on
my laptop and desktop via [termux][termux] where my vim and bash configurations
*just work*.
## Aliases
I have a handful of aliases (defined in `scripts/bin`) that do the large bulk of
the work.
1. `nf`: Create a **n**ote **f**ile in the repo and open it in `$EDITOR`. This
script is rarely invoked directly and is primarily used in subsequent
scripts.
+ Arguments:
+ `$1` must be the note's filename.
+ `$2` may specify an optional subdirectory in the repo to place the file.
I use this to segregate notes by categories such as `work/postmates` or
`personal/jesus` or `unsorted`
+ Examples:
+ `nf medical.md personal/finance`
+ `nf 2019-10-21_devotional.md personal/jesus`
+ `nf todo.md`
2. `N`: Invokes `nf` adding `.md` to the end of the filename.
3. `nd`: Invokes `nf` prefixing the filename with `YYYY-MM-DD_`.
4. `n`: Combines `N` and `nd` resulting in a filename like `$DATE$1.md`.
5. `nsync`: Runs `git add -A && git commit -m Updates && git pull && git push`
in the notes repository.
6. `scn`: Invokes `nf` overriding the `$EDITOR` variable with my spreadsheet
editor.
7. `s`: Invokes `nf _scratch.md` which serves as both a scratchpad for temporary
or very quick notes and as an index for `gf`-jumping (or `fzf`-ing) to other
common files.
## How Could This Improve?
+ Automatic syncing
+ Cron jobs?
+ Building the syncing commands asynchronously into the aliases above?
+ Just add `nsync &> /dev/null &` to each script
+ Possibly hidden behind a flag so it can be disabled
+ Would probably need to add options to `nsync` so that any interactive
stuff (which would fail) gracefully fails and notifies the user
+ Encryption
+ I keep some personal information in these notes that I'd rather not have
exposed on GitHub/GitLab in plaintext.
+ Mobile editing workflow is less than ideal
+ While this isn't necessary, perhaps a way to take good notes on my phone
might improve my workflow
+ Accessibility
+ My notes are really only able to be interacted with from a machine that is
provisioned and setup to do so (read: ssh keys). It might be nice to have
them more available especially to my wife, church, etc. through some web
portal.
+ Currently, I just use a `pbin` command and share the link, which works
well enough.
[sc-im]: https://github.com/lytedev/sc-im
[rg]: https://github.com/BurntSushi/ripgrep
[fd]: https://github.com/sharkdp/fd
[fzf]: https://github.com/junegunn/fzf
[goyo]: https://github.com/junegunn/goyo.vim
[goyo-screenshot]: https://i.imgur.com/pRrzXLz.png
[termux]: https://termux.com

View File

@ -1,3 +1,4 @@
#!/usr/bin/env bash
nf "${1}.md"
fn="${1}"; shift
nf "${fn}.md" $*

View File

@ -1,8 +1,11 @@
#!/usr/bin/env bash
pkill unclutter
sleep 0.1
import ~/.ss.png
chmod 700 ~/.ss.png
< ~/.ss.png xclip -t image/png -i -selection clipboard
< ~/.ss.png xclip -t image/png -i -selection primary
< ~/.ss.png xclip -t image/png -i -selection secondary
< ~/.ss.png xclip -t image/png -i -selection buffer-cut
unclutter &

View File

@ -1,3 +1,4 @@
#!/usr/bin/env bash
N "$(date +%Y-%m-%d)_${1}"
fn="${1}"; shift
N "$(date +%Y-%m-%d)_${fn}.md" $*

View File

@ -1,3 +1,4 @@
#!/usr/bin/env bash
N "$(date +%Y-%m-%d)"
fn="${1}"; shift
N "$(date +%Y-%m-%d)_${fn}" $*

View File

@ -1,15 +1,5 @@
#!/usr/bin/env bash
HOST="ld"
INTERNAL_PUBLIC_DIR="~/../services/data/files/pastes"
f="${1}"
uuid="$(uuid -v 1)"
[ "${f}" == "" ] && echo "No file provided. Exiting." >&2 && exit 2
[ ! -f "${f}" ] && echo "File '$f' does not exist. Exiting." >&2 && exit 1
scp "${f}" "${HOST}:${INTERNAL_PUBLIC_DIR}/${uuid}.txt"
echo "${f} uploaded to https://lyte.dev/pastes/${uuid}.txt"
echo "I recommend checking the file for secrets before sharing."
uuid="$(uuidgen -t)"
upload "${f}" "${uuid}.txt" "pastes"

View File

@ -1,5 +1,3 @@
#!/usr/bin/env bash
SUBDIR="${2:-}"
mkdir -p "$NOTES_PATH/$SUBDIR"
sc-im "$NOTES_PATH/$SUBDIR/$(date +%Y-%m-%d)_$1.sc"
EDITOR="sc-im" nf $*

9
scripts/bin/scrup Executable file
View File

@ -0,0 +1,9 @@
#!/usr/bin/env bash
f="${HOME}/.scrup.png"
pkill unclutter
sleep 0.1
import "${f}"
upload "${f}" "scrup-$(date +%Y-%m-%d_%H-%M-%S).png" "scrots"
unclutter &

View File

@ -1,15 +1,26 @@
#!/usr/bin/env bash
HOST="ld"
INTERNAL_PUBLIC_DIR="~/../services/data/files/uploads"
f="${1}"
fname="$(basename "${f}")"
uuid="$(uuid -v 1)"
fname="${2:-$(basename "${f}")}"
subdir="${3:-uploads}"
internal_dir="/home/daniel/services/data/files/${subdir}"
url="https://lyte.dev/${subdir}/${fname}"
uuid="$(uuidgen -t)"
[ "${f}" == "" ] && echo "No file provided. Exiting." >&2 && exit 2
[ ! -f "${f}" ] && echo "File '$f' does not exist. Exiting." >&2 && exit 1
scp "${f}" "${HOST}:${INTERNAL_PUBLIC_DIR}/${fname}"
ssh ld mkdir -p "${internal_dir}"
rsync_output="$(rsync --stats --ignore-existing "${f}" "${HOST}:${internal_dir}/${fname}")"
num_uploaded="$(<<< "${rsync_output}" grep -oP "Number of created files: \K\d+")"
echo "${f} uploaded to https://lyte.dev/uploads/${fname}"
if [[ $num_uploaded -eq 1 ]]; then
echo "${f} uploaded to ${url}"
elif [[ "$(curl -s -o /dev/null -w "%{http_code}" "${url}")" -eq 200 ]]; then
echo "ERROR: A file already exists at ${url}"
else
echo "${rsync_output}" >> "${HOME}/.upload.log"
echo "ERROR: The file failed to upload - perhaps rsync failed for some reason?\n See \"${HOME}/.upload.log\" for details"
fi