Giter Site home page Giter Site logo

hyde46 / hoard Goto Github PK

View Code? Open in Web Editor NEW
469.0 2.0 22.0 8.74 MB

cli command organizer written in rust

Home Page: https://hyde46.github.io/hoard/

License: MIT License

Rust 96.26% Shell 3.74%
cli tool command command-line-tool rust organizer zsh bash gpt gpt-3

hoard's Introduction

Crates.io version Crates.io version Crates.io version

command organizer tool to hoard all your precious commands πŸ’ŽπŸ‰

Example usage

What is a command organizer?

A command organizer lets you save commands that you often use, but are too complicated or long to remember. For every hoarded command, hoard saves

  • the command ( parameterized with a customizable token, default # )
  • name
  • description
  • namespace where it lives in
  • tags ( Optional )

If you get lost in your massive command history, and can't find for example a specific docker command out of thousand docker commands you've already ran, just hoard it. With a name and description it will be much easier to find again. When you look for that command again a month later, take a look at your hoarded commands.

hoard is not supposed to replace shell history finder like fzf atuin or similar utilities. It rather should be used in conjunction with them.

Now with chatGPT integration πŸ’Ž

πŸ’Œ Table of contents

From source

It's best to use rustup to get setup with a Rust toolchain, then you can run:

cargo install hoard-rs

Or build it yourself:

cargo build --release

Find the binaries in ./target/release/hoard Move it to wherever you need it ( Like /usr/local/bin/hoard ) Or run

cargo install --path .

Linux

Tested on:

  • Ubuntu
  • Arch
  • EndeavourOS

Install hoard by running

./install.sh

If you are running fish shell

LATEST_RELEASE=1.4.2 ./install.fish

AUR (Arch Linux)

paru -S hoard

Homebrew (macOS)

brew tap Hyde46/hoard
brew install hoard

MacPorts (macOS)

sudo port install hoard-cli

More info here

Windows

Best to install from source, good luck

Autocomplete with Shell plugin

Install hoard as a plugin to enable autocomplete. Depending on your shell, run one of the following commands. To keep it installed for your next shell session, add the source command with an absolute path to your .bashrc or copy-paste the plugins content to your .bashrc.

bash

source src/shell/hoard.bash

zsh

source src/shell/hoard.zsh

fish

source src/shell/hoard.fish

Nix

The hoard package is in the nixpkgs package repository.

Either install it with nix-env -iA hoard, get it temporarily with nix-shell -p hoard or add it to your configuration.

Save a new command

hoard new

If a parameter is not known when saving the command, put a # ( Or your customized token from your ~/.config/hoard/config.yml ) You can also name your parameters like this:

echo "My name is #first and I live at #city. Did I tell you my name, #first?" 

When putting #first you only have to do it once for each occurrence in the command. A parameter name is defined as everything followed by the token until the first space character is found. Alternatively you can determine where the named parameter ends by putting a ! ( Or your customized token from your ~/.config/hoard.config.yml)

echo "My name is #first named parameter! and I live at #city. Did I tell you my name, #first?" 

Search through command trove

<Ctrl-h>

Or alternatively, if not installed as a plugin, the interactive search can still be performed, though without autocomplete. This assumes the user to copy the command by mouse from the UI

hoard list

When running hoard list as a shell plugin and selecting a parameterized command, hoard will ask for all missing parameters to input before sending the complete command to your shell input.

If there is a trove.yml file present in the local directory, hoard will only load this trove file and not display your "global" trove! ( Edit ~/.config/hoard/config.yml read_from_current_directory to disable )

chatGPT integration

When running hoard list or through the hoard shortcut, press Ctrl-a to be asked for a prompt. Desribe what your command is supposed to do, and chatGPT will create and hoard a new command based on your prompt.

If you dont already have an OpenAI account to generate an API key, head to this page. ( Given the low amount of tokens consumed, this is extremly cheap. ~ 0.01$ for 30 generated commands )

You either need to set the env variable

export OPENAI_API_KEY=abcabcabc

Or for a permanent solution set gpt_api_key in your ~/.config/hoard/config.yml

chatGPT does not always reply in the same format. Sometimes the resulting command will be added to the description. Use the edit mode <TAB>/<Ctrl-E> to edit the hoarded command to its correct form.

Synchronize commands with another terminal

You can keep your commands in sync in multiple terminals by using hoard sync

First register a new account

hoard sync register

Then login with your new account

hoard sync login

Save your local commands online

hoard sync save

Login with the same account on a different computer/terminal and then run

hoard sync get

This will merge your local trove file with the cloud-based one. You will get prompted how to handle collisions if there are any. However, if you are unhappy with how the merge happened, you've got the option to revert the latest hoard sync get command

hoard sync revert

If you want to host your own sync server, checkout it's repository. Then, update your config file to point to the new server location ~/.config/hoard/config.yml

Delete a command

hoard remove <name>

Delete all commands in a namespace

hoard remove_namespace <namespace_name>

Edit a command

hoard edit <name>

Info

Shows location of config file and trove file

hoard info

Set parameter token

Change parameter token of config file

hoard set_parameter_token <parameter_token>

Import other trove files from trove.yml or urls pointing to a trove.yml file

hoard import /path/to/trove.yml

or

hoard import https://troves.com/new_trove.yml

Export trove file

hoard export /path/to/exported/trove.yml

Show list of commands in the GUI

<F1>

Next item in command list

<Ctrl-N> / <Down-Arrow>

Previous item in command list

<Ctrl-P> / <Ctrl-Y> / <Up-Arrow>

Next namespace tab

<Ctrl-L> / <Right-Arrow>

Previous namespace tab

<Ctrl-H> / <Left-Arrow>

Select command

<Enter>

Quit

<Esc> / <Ctrl-D> / <Ctrl-C> / <Ctrl-G>

hoard's People

Contributors

a-kenji avatar affanshahid avatar aziks0 avatar builditluc avatar dependabot[bot] avatar dfirebird avatar gautamprikshit1 avatar herbygillot avatar hyde46 avatar kyoto7250 avatar lordmzte avatar orhun avatar qb60 avatar shirtpantswallet avatar victorkuenstler avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

hoard's Issues

Colorize parameter token

When filling out a parameterized command, colorize the parameter token different to the rest of the command

`info` subcommand

Add subcommand to show general info

  • Where config file is located at
  • Where trove file is located at
    -....

add command to print shell configs

It'd be great to have a command like hoard shell-config $SHELL that could be used like hoard shell-config fish | source in order to ship shell configs embedded in the binary. This has the advantage of allowing shell configs to be automatically updated without the user having to do anything.

I'd like to create a PR for this :D

Allow escape character

Enable escaping characters in the saved command.
This would let users store commands with commands that carry the same characters as the parameter tokens (like # and ! for denoting the start and end of a named parameter in a default configuration).

Example Trove files

Create a bunch of trove files in /examples for users to import, which also indicates how trove files are supposed to be used.
Needs #60 to be finished to be integrated nicely ( parameterized commands )

Exemplary trove files with themes:

  • git
  • docker build
  • ffmpeg
  • curl calls to specific API endpoint?
    ...

Command text does not wrap to next line in UI

Running hoard list and selecting a command cuts the command off in the GUI if it is too long.
Look for the right TUI wrapper to wrap the text to the next line(s).
Relevant piece of code here
Wrap the text block with
.wrap(Wrap { trim: true })

Add clipboard functionality

Add option to save commands to clipboard.
Useful if hoard list is not run with autocomplete as shell plugin

Move hoard config

Currently hoard config resides at ~/.config/.hoard
Rename .hoard to hoard.
Write small procedure checking if a user still has his trove.yml and/or config.yml in .hoard and copy over these files to the new home directory ~/.config/hoard/

suggest: read trove.yml in the current directory (or load with option)

Many projects use Makefile, gradle, and npm and more to configure commands for their project, but we often need to read the code inside because those tools are difficult to write a detailed description.

If hoard have the ability to read trove.yml in the current directory, we will be able to search for those commands and give them descriptions.

This makes it possible to add trove.yml to each repository to manage commands.

# project root
Makefile # declare command
trove.yml # search, and execute in Makefile command.

Whether to load automatically or optionally needs to be discussed.

[Feature Request] Add path autocomplete to parameter tokens

Thanks for the nice tool. πŸš€
Often I end up having to type in different paths into what is essentially the same command. So basically have the path be a parameter but then either type the whole path or c&p it from a different terminal window. Here an autocompletion of path parameters would be super useful

Empty default values for dialoguer result in empty commands

See here for example.
This is true for all with_<x>_input() methods.
The idea is to allow supplying Option<String> for a default prompt.
However, currently if the default prompt is None, the default prompt from dialoguer is an empty string.

To fix this:
only add .default() to the Input object if the default_value is Some

Allow name-based / num-based parameter tokens

For example, I have a command that reuses a parameter many times like this:
echo hello #; echo I hope you find this message well, #; echo goodbye, #

Although there are three # placeholders, they are all for the same param.
If I put such a command into hoard today, when picking it, I will have to supply the same name "John" 3 times to get
echo hello John; echo I hope you find this message well, John; echo goodbye, John

What if I can tell hoard that those are the same parameter, such as:
echo hello #name; echo I hope you find this message well, #name; echo goodbye, #name
And when picking the command, instead of being asked for the first, second, and third params, I simply get asked for the name param?

Check for updates

On start check for availble updates.
Compare running version of hoard with latest tag on github repository
Inform user of available update

fix clippy lints

Looks like cargo clippy currently spits out about 450 lines of warnings. I think we should work towards reducing that number.

add Cargo.lock file to the repo

Hey!

I want to package hoard for nixpkgs and it would be nice if you could commit the Cargo.lock file.
Are there any releases planned because the last one was 6 months ago?

Thanks!

Command with optional parameters

Currently a command is a string. But it should be a union of string and an object. So, we should make this a struct with optional arguments.

Proposal:

struct HoardCommandd {
command: String,
args: Vec<Arg>
}

struct Arg {
name: String,
value: Optional<String>
}

So if you run a command with args with no default value, there should spawn an interactive shell.

autocomplete does not work on osx with bash

OSX 12.3
Installed via brew
Shell: bash

When selecting a command via the \c-h menu and using hoard.bash, it returns to bash without any text filled out.

Changing the system shell to zsh chsh -s /bin/zsh and using hoard.zsh, it does work as expected.

Export functionality

Add export subcommand.
Asks the user for one or multiple namespaces, and/or single commands to export as a valid trove.yml file

Probably doesn't work on zsh+macos

I just stumbled upon this project (I'm a maintainer of atuin and it popped up in a search I made).

I notice you have a similar shell setup and managed to get crossterm to work, something we were struggling with.

Upon further inspection, it doesn't seem like you do anything different so I actually think it doesn't work for you, but only on ZSH + MacOS.

I came to this conclusion: atuinsh/atuin#331 (comment)
sharing it here since you may also run into it at some point

Brew SHA mismatch

Thanks for this project!
I wanted to check it out, but following the README instructions leads me to

❯ brew install hoard
==> Downloading https://github.com/Hyde46/hoard/releases/download/v1.0.0/hoard_v1.0.0_x86_64-apple-darwin.zip
==> Downloading from https://objects.githubusercontent.com/github-production-release-asset-2e65be/382835373/8d721b0f-19b
######################################################################## 100.0%
Error: hoard: SHA256 mismatch
Expected: f2ea22201c2490f5cebb27b53d50bff1745de784f699e8807013f9cc29828a63
  Actual: 2e53a1511a0b691e636f6236d7b468368806310808ef63d937707c648dee2d52
    File: /home/asdf/.cache/Homebrew/downloads/4e65b03a87b5c0da5c600058b00e641f48b2527e711365d917e85b2a22c5350f--hoard_v1.0.0_x86_64-apple-darwin.zip
To retry an incomplete download, remove the file above.

Would you be able to update the project?

[feature request] Add/remove/move/edit commands in TUI

Awesome program! πŸš€
Would it be possible to allow editing the trove interactively in the TUI? I think it would be more convenient to browse the hoarded commands and edit them directly in the same interface, instead of browsing Β» remembering the name of a command Β»hoard edit # Β» browsing again.

Allow ending parameter token

Also allow ending parameter token, so that name parameter can be defined without needing to have white space at the end.

for example sudo find / -iname "*#string*"
here hoard replaces everything after "#" unless you put a space after "#string".
Possible solution, we can define another parameter token like "@" or use same token twice for ending.
sudo find / -iname "*#string@*" sudo find / -iname "*#string##*"

#151

Parameterized Commands

Add Parameters support for hoarded commands.
When selecting/ running a command with parameters, start dialogue, asking for all parameters

Use struct arguments

The clap crate somewhat recently got the ability to declare command-line arguments as a struct as opposed to the current yaml solution. If we used this feature, we could could clean up the current code, as instead of something like sub_m.value_of("arg"), getting an argument would be as simple as accessing a struct field: sub_m.arg. This also increases performance, as there will no longer be a need to parse the yaml file declaring the arguments on every startup.

Clap got this feature in 3.0.0, but hoard is currently still on 2.33.3, so an upgrade would be necessary.

Help page in GUI

Add a overlay or separate page in the GUI, showing keyboard shortcuts

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.