A "key-value" utility for UNIX-like systems.
Allows to conveniently store values and retrieve them by key. stringp considers a directory to be a key-value storage, containing files with names, where a filename is a key, and a content of a file is a value.
Creates a new file and writes everything that was passed to stdin into it. If stdin is empty, the new file will also be empty.
cat content.txt | stringp add 'key'
cat content.txt | stringp a 'key'In this example, a file named key will be created with the contents of the file content.txt.
Outputs the value by key:
stringp get key
stringp g keyIf such a key does not exist, nothing will be displayed, and the program will terminate with code 1.
You can also add arguments to your files!
For example: ${arg1}
Or: ${arg2}
Arguments are passed via stdin in JSON format:
echo '{"arg1":"value1","arg2":"value2"}' | stringp get keyThen you will get the following output:
You can also add arguments to your files!
For example: value1
Or: value2
The key command makes it easier to generate arguments for the get command:
stringp key arg valueThis command will generate the following output:
{"arg":"value"}
This command can be used in pipelines to add more keys and values:
stringp k arg1 value1 | stringp k arg2 value2 This command will generate the following output:
{"arg1":"value1","arg2":"value2"}
The following two examples are completely equivalent:
stringp k arg1 value1 | stringp k arg2 value2 | stringp g keyecho '{"arg1":"value1","arg2":"value2"}' | stringp get keyIf you need to leave a string like ${string} untouched in a file, there are several ways to do this:
- Do not pass an argument with that name.
- Replace
${string}with$\{string}and use the-sflag, which will replace\{with{.
Delete file by key.
stringp remove key
stringp rm keyOutputs a list of existing keys:
stringp list
stringp keys
stringp lOpens a file named by the key in storage directory with the editor from $EDITOR, if it exists. If not, it tries to open editor, nano, vim or vi.
stringp edit key
EDITOR=nvim stringp edit keyBy changing the directory, you can change the "database" and have the one you need for each case. Hierarchy:
--dir- Environment variable
STRING_POOL_DIR - Use
~/.local/share/string-pooldirectory by default, if exists
stringp get key --dir .
stringp get --dir . key
STRING_POOL_DIR="." stringp get key
stringp get key #~/.local/share/string-pool by defaultPrints current String Pool directory.
stringp dirYou can use fzf or similar tools to find and select the desired key and get the value:
stringp get $(stringp keys | fzf)Another similar example: You can conveniently display all available keys using wofi or rofi, find and select the one you need, and then, for example, copy the value to the clipboard.
stringp get "$(stringp keys | wofi --dmenu)" | wl-copyThis can be useful if you often write in markup languages such as LaTeX and frequently forget certain template elements. You can also bind this command to any key combination, depending on your shell.
For example, we can add this template for LaTeX:
\begin{figure}[H]
\centering
\includegraphics[width=0.6\textwidth]{${src}}
\end{figure}The following command will display the fzf menu, where you can select the path to the image. This path will then be inserted into the template, and the template will be copied to the clipboard:
stringp k src $(fzf) | stringp g latex-picture | wl-copy
You can also make more complex templates, for example, here is one of mine for pandoc:
---
title: "**${title}**"
author: "${name}"
date: "${date}"
lang: "ru"
fontsize: 12pt
geometry: a4paper
mainfont: "LiberationSans"
header-includes: |
\usepackage{xcolor}
\usepackage{float}
\usepackage{hyperref}
\geometry{left=2cm,right=2cm,top=2cm,bottom=2cm}
\hypersetup{
colorlinks=true,
linkcolor=blue,
urlcolor=blue,
bookmarksopen=true,
bookmarksopenlevel=10
}
\usepackage{graphicx}
\usepackage{multicol}
\setlength{\columnsep}{1.5cm}
output: pdf_document
pdf-engine: xelatex
---
You can store links, file paths, or MAC addresses and use them in your scripts, and easily change the values if necessary.
git clone "$(stringp get server-user)@$(stringp get server-ip):/path/to/gitrepo/$(gum input --placeholder='Repo name')"git clone https://github.com/AndyLocks/string-pool ; cd string-pool
cargo build --releaseThe binary can be found in ./target/release directory.
install -Dm755 ./target/release/stringp /usr/bin/stringpinstall -Dm644 ./stringp.1.gz /usr/share/man/man1/stringp.1.gzmkdir -p "/usr/share/bash-completion/completions"
mkdir -p "/usr/share/zsh/site-functions"
mkdir -p "/usr/share/fish/vendor_completions.d"
"/usr/bin/stringp" completions bash > "/usr/share/bash-completion/completions/stringp"
"/usr/bin/stringp" completions zsh > "/usr/share/zsh/site-functions/_stringp"
"/usr/bin/stringp" completions fish > "/usr/share/fish/vendor_completions.d/stringp.fish"install -Dm644 LICENSE "/usr/share/licenses/stringp/LICENSE"