Skip to content

Commit

Permalink
Update CHANGELOG and README to v0.0.3.
Browse files Browse the repository at this point in the history
  • Loading branch information
marcopaganini committed Sep 1, 2024
1 parent 9c92001 commit 94f94f0
Show file tree
Hide file tree
Showing 3 changed files with 101 additions and 41 deletions.
37 changes: 37 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,40 @@
# Version 0.0.3

* Add git repository sync support: To use, create a free repository on your
git provider of choice (github, gitlab, etc...) and use `snip repo
<your_repo_url>` to initialize the repository sync. This will also run the
first sync. From this point on, use `snip sync` to synchronize changes.
Both your configuration file and database will be synced.

* Added multi-host support: When using git sync, you can use the same
repository across multiple hosts. There's a new field, "HOST", in the
database and FZF will also search by host when recalling a snippet with
`Ctrl-X/Ctrl-R` or `snip find`. V0.0.3 should automatically migrate the
database from previous versions.

* New commands: Besides `snip repo` and `snip sync` (described above),
there's now a `snip log` command that shows you the history of your
repository sync changes.

* Changed the way `Ctrl-X/Ctrl-R` works: Now, you won't see a `snip add`
command on the command-line that requires ENTER to execute. Instead, `snip
add` will be called directly, for a cleaner experience.

* Better input sanitization: Explicitly checks for "|" (pipe characters) in
the description and rejects the input. Pipes cannot be used in the
description as they're also used as field separators in the database.

* You can now set the default editor in your config file (`SNIP_EDITOR`).
Thanks hrfried for the PR!

* Added emojis to some messages, for your viewing pleasure. :)

* Config file changes: Previously, we used a file called `config` for all
configurations. This file is now suffixed by the hostname. This was changed
so that we can easily sync multiple host configs without git conflicts.
Also, on the first run, snip will now generate a fully commented out config
file, and rely on internal defaults.

# Version 0.0.2

* Added [bat](https://github.com/sharkdp/bat) support. If you have `bat`
Expand Down
83 changes: 53 additions & 30 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
useful and important bash code snippets directly from the bash prompt. It is
especially useful to save long one-liners, or rarely used commands which we tend
to forget. `snip` is written in pure bash, but uses
[fzf](https://github.com/junegunn/fzf) to allow the user to perform searches on
[FZF](https://github.com/junegunn/fzf) to allow the user to perform searches on
the snippet database.

![Screen Cast](https://raw.githubusercontent.com/marcopaganini/snip/master/assets/snip.gif)
Expand All @@ -17,9 +17,9 @@ the snippet database.

Shell scripting is a powerful tool in the right hands. The piping capabilities
coupled with the many readily available utilities make it possible to perform
complex and useful operations on all sorts of data. Most medium to advanced bash
users will have a number of these stored somewhere, from text files to
[Google Keep](http://keep.google.com). Those solutions involve cutting and
complex and useful operations on all sorts of data. Most medium to advanced
bash users will have a number "code snippets" stored somewhere, from text files
to [Google Keep](http://keep.google.com). Those solutions involve cutting and
pasting, and in the case of web-based solutions, the use of a browser.

Consider for example the following sequence of commands, taken from a real use
Expand All @@ -38,10 +38,9 @@ It took a few tries to get the command "just right", which naturally filled the
history with all sorts of invalid or "almost valid" commands.

With `snip`, it's just be a matter of typing `Ctrl-x` `Ctrl-n` ("N" for "new")
directly at the command-line prompt to save the snippet when the correct command
shows. To find and recall a saved snippet just type `Ctrl-x` `Ctrl-R` ("R" for
"Run"). This will fill-in the command-line prompt with the command, ready to
execute.
directly at the command-line prompt to save the snippet when the correct
command shows. To find and recall a saved snippet just type `Ctrl-x` `Ctrl-R`
("R" for "Run", or "Recall").

## Features

Expand All @@ -50,15 +49,16 @@ execute.
* Uses a simple text file for the database.
* CLI commands to edit the database manually.
* CLI commands to list the contents of the database in a formatted way.
* Supports syncing of multiple hosts via a git repo.
* Automatically saves a time stamp with the command.
* Written in pure shell. To install just copy one file to `/usr/local/bin` or
any other location in your `PATH`.
* Displays full usage with a simple command (`snip help`).

## Installation

Installation is easy. Just cut & paste the two lines below. To "upgrade" snip,
just repeat the same commands:
Installation is easy. Just cut & paste the two lines below. To upgrade snip,
to the latest stable version, just repeat the same commands:

```
sudo curl -s https://raw.githubusercontent.com/marcopaganini/snip/master/snip >/usr/local/bin/snip
Expand Down Expand Up @@ -87,7 +87,7 @@ configuration:
replace the current line with a `snip add` command to insert your snippet
into the database. Just hit ENTER afterwards and provide a description.

* `Ctrl-X` `Ctrl-R`: This starts fzf so the user can choose a command to be
* `Ctrl-X` `Ctrl-R`: This starts FZF so the user can choose a command to be
recalled. The command is inserted in the current command-line input. If no
modifications are required, just hit ENTER to execute the command.

Expand All @@ -101,18 +101,16 @@ typing `snip help`.
`snip` is in its early stages and I have a number of ideas for future features.
Some ideas:

* A bit more color in the fzf selector for those who prefer it.
* git integration - commit and pull your snippets automatically from your
repo.
* A bit more color in the FZF selector for those who prefer it.
* zsh integration.
* A `snip delete` command (right now, use `snip edit` and delete the snippet
line directly from your editor.)
* Other general improvements.

## Similar options

* [https://github.com/knqyf263/pet](https://github.com/knqyf263/pet) - pet is a snippet manager written in Go.
if you like snip, you may like pet too.
* [https://github.com/knqyf263/pet](https://github.com/knqyf263/pet) - pet is
a snippet manager written in Go. if you like snip, you may like pet too.

## Comments and ideas

Expand Down Expand Up @@ -153,12 +151,14 @@ OPTIONS
text file using '|' (pipe) as a delimiter. Every line needs to have
three exact fields: timestamp, description, and command. It is
acceptable for the command to contain pipe characters, but not for
the timestamp or description fields.
the timestamp or description fields. Please note that you can only
edit the current host database (even though list and find will by
default show the contents of all hosts).
find [-q, --query STRING]
The find command invokes fzf on the database and prints the
The find command invokes FZF on the database and prints the
command-line for the snippet chosen by the user. The `--query` flag
sets the initial query for fzf, if present.
sets the initial query for FZF, if present.
help
This helpful message. :)
Expand All @@ -167,6 +167,15 @@ OPTIONS
The list command issues a formatted listing of the snippet database,
including the snippet creation timestamps.
log
Show a git log --oneline of the database directory.
repo <reponame>
Initializes a git repository and start database sync. <reponame>
must be an URL pointing to a git repository. TIP: You can create
private repos in github or gitlab for free and use them to sync your
snippets.
setup
This command issues the required commands to setup the bash
command-line bindings to easily add snippets and re-run saved
Expand All @@ -184,23 +193,32 @@ OPTIONS
confirm the action and enter a description.
Ctrl-X Ctrl-R
Find and run a saved snippet. This will open an fzf window and
Find and run a saved snippet. This will open an FZF window and
allow the user to choose a snippet to run. Once selected, snip
will replace the current bash input buffer with the command to
run.
sync
Sync local changes with the git repository. This adds any changes
to your database file, commits it and does a git pull -r (rebase)
followed by a git push. The database name contains the host name
so there should be no conflicts. If anything unusual happen, snip
will abort execution with an error message.
version
Show the program version.
SETUP
Just add `eval "$(/path/to/snip setup)"` to your `~/.bashrc`. Depending on your
setup, you may need to add it to `~/.profile` as well).
Just add `eval "$(/path/to/snip setup)"` to your `~/.bashrc`. Depending
on your setup, you may need to add it to `~/.profile` as well).
CONFIGURATION FILE
On the first run, snip will create a configuration file with default
values.
On the first run, snip will create an example configuration file with
default values commented out.
Currently, it is possible to override a few items in the config file.
To do that, edit `~/.config/snip/config` and/edit add the following:
Currently, it is possible to override a few items in the config file. To
do that, edit `~/.config/snip/config.${HOSTNAME}` and/edit add the
following:
# bash keybindings
#
Expand All @@ -212,25 +230,30 @@ CONFIGURATION FILE
SNIP_BIND_FIND='"\C-x\C-r"'
# bat (aka batcat) theme. If you have batcat installed, snip will
# automatically use it to syntax highlight the snippets in the fzf preview
# automatically use it to syntax highlight the snippets in the FZF preview
# window. You can override the theme using the setting below.To see all
# available themes, run `cat --list-themes` (or `batcat --list-themes`
# in some distributions.)
BAT_THEME="gruvbox-dark"
The lines above show the default keybindings to add and run commands.
Please keep in mind that this file is sourced directly by the main
program, so it should be a valid bash file. Look for the the key syntax
for "bind -x" in the bash manpage for details.
# This overrides the default editor (normallly $VISUAL or $EDITOR)
# Common choiceses are nano, nvim, vim, etc.
SNIP_EDITOR="nano"
REQUIREMENTS
This program requires FZF to run (https://github.com/junegunn/fzf). Please note that
fzf is very popular and available natively in most Linux distributions.
FZF is very popular and available natively in most Linux distributions.
If installed, snip will use `batcat` (aka bat) to provide syntax highlighting
in the preview window.
AUTHOR
(C) Aug/2024 by Marco Paganini <paganini [at] paganini [dot] net>
(C) Sep/2024 by Marco Paganini <paganini [at] paganini [dot] net>
```
22 changes: 11 additions & 11 deletions snip
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@
# default show the contents of all hosts).
#
# find [-q, --query STRING]
# The find command invokes fzf on the database and prints the
# The find command invokes FZF on the database and prints the
# command-line for the snippet chosen by the user. The `--query` flag
# sets the initial query for fzf, if present.
# sets the initial query for FZF, if present.
#
# help
# This helpful message. :)
Expand Down Expand Up @@ -72,7 +72,7 @@
# confirm the action and enter a description.
#
# Ctrl-X Ctrl-R
# Find and run a saved snippet. This will open an fzf window and
# Find and run a saved snippet. This will open an FZF window and
# allow the user to choose a snippet to run. Once selected, snip
# will replace the current bash input buffer with the command to
# run.
Expand All @@ -92,11 +92,12 @@
# on your setup, you may need to add it to `~/.profile` as well).
#
# CONFIGURATION FILE
# On the first run, snip will create a configuration file with default
# values.
# On the first run, snip will create an example configuration file with
# default values commented out.
#
# Currently, it is possible to override a few items in the config file.
# To do that, edit `~/.config/snip/config` and/edit add the following:
# Currently, it is possible to override a few items in the config file. To
# do that, edit `~/.config/snip/config.${HOSTNAME}` and/edit add the
# following:
#
# # bash keybindings
# #
Expand All @@ -108,7 +109,7 @@
# SNIP_BIND_FIND='"\C-x\C-r"'
#
# # bat (aka batcat) theme. If you have batcat installed, snip will
# # automatically use it to syntax highlight the snippets in the fzf preview
# # automatically use it to syntax highlight the snippets in the FZF preview
# # window. You can override the theme using the setting below.To see all
# # available themes, run `cat --list-themes` (or `batcat --list-themes`
# # in some distributions.)
Expand All @@ -127,14 +128,13 @@
#
# REQUIREMENTS
# This program requires FZF to run (https://github.com/junegunn/fzf). Please note that
# fzf is very popular and available natively in most Linux distributions.
# FZF is very popular and available natively in most Linux distributions.
#
# If installed, snip will use `batcat` (aka bat) to provide syntax highlighting
# in the preview window.
#
# AUTHOR
# (C) Aug/2024 by Marco Paganini <paganini [at] paganini [dot] net>
#
# (C) Sep/2024 by Marco Paganini <paganini [at] paganini [dot] net>

set -o nounset

Expand Down

0 comments on commit 94f94f0

Please sign in to comment.