Coder Social home page Coder Social logo

pet's Introduction

pet : CLI Snippet Manager

GitHub release MIT License

Simple command-line snippet manager, written in Go

You can use variables (<param> or <param=default_value> ) in snippets.

Abstract

pet is written in Go, and therefore you can just grab the binary releases and drop it in your $PATH.

pet is a simple command-line snippet manager (inspired by memo). I always forget commands that I rarely use. Moreover, it is difficult to search them from shell history. There are many similar commands, but they are all different.

e.g.

  • $ awk -F, 'NR <=2 {print $0}; NR >= 5 && NR <= 10 {print $0}' company.csv (What I am looking for)
  • $ awk -F, '$0 !~ "DNS|Protocol" {print $0}' packet.csv
  • $ awk -F, '{print $0} {if((NR-1) % 5 == 0) {print "----------"}}' test.csv

In the above case, I search by awk from shell history, but many commands hit.

Even if I register an alias, I forget the name of alias (because I rarely use that command).

So I made it possible to register snippets with description and search them easily.

TOC

Main features

pet has the following features.

  • Register your command snippets easily.
  • Use variables (with one or several default values) in snippets.
  • Search snippets interactively.
  • Run snippets directly.
  • Edit snippets easily (config is just a TOML file).
  • Sync snippets via Gist or GitLab Snippets automatically.

Parameters

There are <n_ways> ways of entering parameters.

They can contain default values: Hello <subject=world> defined by the equal sign.

They can even contain <content=spaces & = signs> where the default value would be <content=spaces & = signs>.

Default values just can't <end with spaces >.

They can also contain multiple default values: Hello <subject=|_John_||_Sam_||_Jane Doe = special #chars_|>

The values in this case would be :Hello <subject=|_John_||_Sam_||_Jane Doe = special #chars_|>

Examples

Some examples are shown below.

Register the previous command easily

By adding the following config to .bashrc or .zshrc, you can easily register the previous command.

bash prev function

function prev() {
  PREV=$(echo `history | tail -n2 | head -n1` | sed 's/[0-9]* //')
  sh -c "pet new `printf %q "$PREV"`"
}

zsh prev function

$ cat .zshrc
function prev() {
  PREV=$(fc -lrn | head -n 1)
  sh -c "pet new `printf %q "$PREV"`"
}

fish

See below for details.
https://github.com/otms61/fish-pet

Select snippets at the current line (like C-r) (RECOMMENDED)

bash

By adding the following config to .bashrc, you can search snippets and output on the shell. This will also allow you to execute the commands yourself, which will add them to your shell history! This is basically the only way we can manipulate shell history. This also allows you to chain commands! Example here

$ cat .bashrc
function pet-select() {
  BUFFER=$(pet search --query "$READLINE_LINE")
  READLINE_LINE=$BUFFER
  READLINE_POINT=${#BUFFER}
}
bind -x '"\C-x\C-r": pet-select'

zsh

$ cat .zshrc
function pet-select() {
  BUFFER=$(pet search --query "$LBUFFER")
  CURSOR=$#BUFFER
  zle redisplay
}
zle -N pet-select
stty -ixon
bindkey '^s' pet-select

fish

See below for details.
https://github.com/otms61/fish-pet

Copy snippets to clipboard

By using pbcopy on OS X, you can copy snippets to clipboard.

Features

Edit snippets

The snippets are managed in the TOML file, so it's easy to edit.

Sync snippets

You can share snippets via Gist.

Hands-on Tutorial

To experience pet in action, try it out in this free O'Reilly Katacoda scenario, Pet, a CLI Snippet Manager. As an example, you'll see how pet may enhance your productivity with the Kubernetes kubectl tool. Explore how you can use pet to curated a library of helpful snippets from the 800+ command variations with kubectl.

Usage

pet - Simple command-line snippet manager.

Usage:
  pet [command]

Available Commands:
  configure   Edit config file
  edit        Edit snippet file
  exec        Run the selected commands
  help        Help about any command
  list        Show all snippets
  new         Create a new snippet
  search      Search snippets
  sync        Sync snippets
  version     Print the version number

Flags:
      --config string   config file (default is $HOME/.config/pet/config.toml)
      --debug           debug mode

Use "pet [command] --help" for more information about a command.

Snippet

Run pet edit
You can also register the output of command (but cannot search).

[[snippets]]
  command = "echo | openssl s_client -connect example.com:443 2>/dev/null |openssl x509 -dates -noout"
  description = "Show expiration date of SSL certificate"
  output = """
notBefore=Nov  3 00:00:00 2015 GMT
notAfter=Nov 28 12:00:00 2018 GMT"""

Run pet list

    Command: echo | openssl s_client -connect example.com:443 2>/dev/null |openssl x509 -dates -noout
Description: Show expiration date of SSL certificate
     Output: notBefore=Nov  3 00:00:00 2015 GMT
             notAfter=Nov 28 12:00:00 2018 GMT
------------------------------

Configuration

Run pet configure

[General]
  snippetfile = "path/to/snippet" # specify snippet directory
  editor = "vim"                  # your favorite text editor
  column = 40                     # column size for list command
  selectcmd = "fzf"               # selector command for edit command (fzf or peco)
  backend = "gist"                # specify backend service to sync snippets (gist or gitlab, default: gist)
  sortby  = "description"         # specify how snippets get sorted (recency (default), -recency, description, -description, command, -command, output, -output)
  cmd = ["sh", "-c"]              # specify the command to execute the snippet with

[Gist]
  file_name = "pet-snippet.toml"  # specify gist file name
  access_token = ""               # your access token
  gist_id = ""                    # Gist ID
  public = false                  # public or priate
  auto_sync = false               # sync automatically when editing snippets

[GitLab]
  file_name = "pet-snippet.toml"  # specify GitLab Snippets file name
  access_token = "XXXXXXXXXXXXX"  # your access token
  id = ""                         # GitLab Snippets ID
  visibility = "private"          # public or internal or private
  auto_sync = false               # sync automatically when editing snippets

Selector option

Example1: Change layout (bottom up)

$ pet configure
[General]
...
  selectcmd = "fzf"
...

Example2: Enable colorized output

$ pet configure
[General]
...
  selectcmd = "fzf --ansi"
...
$ pet search --color

Tag

You can use tags (delimiter: space).

$ pet new -t
Command> ping 8.8.8.8
Description> ping
Tag> network google

Or edit manually.

$ pet edit
[[snippets]]
  description = "ping"
  command = "ping 8.8.8.8"
  tag = ["network", "google"]
  output = ""

They are displayed with snippets.

$ pet search
[ping]: ping 8.8.8.8 #network #google

You can exec snipet with filtering the tag

$ pet exec -t google

[ping]: ping 8.8.8.8 #network #google

Sync

Gist

You must obtain access token. Go https://github.com/settings/tokens/new and create access token (only need "gist" scope). Set that to access_token in [Gist] or use an environment variable with the name $PET_GITHUB_ACCESS_TOKEN.

After setting, you can upload snippets to Gist.
If gist_id is not set, new gist will be created.

$ pet sync
Gist ID: 1cedddf4e06d1170bf0c5612fb31a758
Upload success

Set Gist ID to gist_id in [Gist]. pet sync compares the local file and gist with the update date and automatically download or upload.

If the local file is older than gist, pet sync download snippets.

$ pet sync
Download success

If gist is older than the local file, pet sync upload snippets.

$ pet sync
Upload success

Note: -u option is deprecated

GitLab Snippets

You must obtain access token. Go https://gitlab.com/-/profile/personal_access_tokens and create access token. Set that to access_token in [GitLab] or use an environment variable with the name $PET_GITLAB_ACCESS_TOKEN.

You also have to configure the url under [GitLab], so pet knows which endpoint to access. You would use url = "https://gitlab.com"unless you have another instance of Gitlab.

At last, switch the backend under [General] to backend = "gitlab".

After setting, you can upload snippets to GitLab Snippets. If id is not set, new snippet will be created.

$ pet sync
GitLab Snippet ID: 12345678
Upload success

Set GitLab Snippet ID to id in [GitLab]. pet sync compares the local file and gitlab with the update date and automatically download or upload.

If the local file is older than gitlab, pet sync download snippets.

$ pet sync
Download success

If gitlab is older than the local file, pet sync upload snippets.

$ pet sync
Upload success

Auto Sync

You can sync snippets automatically. Set true to auto_sync in [Gist] or [GitLab]. Then, your snippets sync automatically when pet new or pet edit.

$ pet edit
Getting Gist...
Updating Gist...
Upload success

Installation

You need to install selector command (fzf or peco).
homebrew install fzf automatically.

Binary

Go to the releases page, find the version you want, and download the zip file. Unpack the zip file, and put the binary to somewhere you want (on UNIX-y systems, /usr/local/bin or the like). Make sure it has execution bits turned on.

Mac OS X / Homebrew

You can use homebrew on OS X.

$ brew install knqyf263/pet/pet

If you receive an error (Error: knqyf263/pet/pet 64 already installed) during brew upgrade, try the following command

$ brew unlink pet && brew uninstall pet
($ rm -rf /usr/local/Cellar/pet/64)
$ brew install knqyf263/pet/pet

RedHat, CentOS

Download rpm package from the releases page

$ sudo rpm -ivh https://github.com/knqyf263/pet/releases/download/v0.3.0/pet_0.3.0_linux_amd64.rpm

Debian, Ubuntu

Download deb package from the releases page

$ wget https://github.com/knqyf263/pet/releases/download/v0.3.6/pet_0.3.6_linux_amd64.deb
dpkg -i pet_0.3.6_linux_amd64.deb

Archlinux

Two packages are available in AUR. You can install the package from source:

$ yaourt -S pet-git

Or from the binary:

$ yaourt -S pet-bin

Build

$ mkdir -p $GOPATH/src/github.com/knqyf263
$ cd $GOPATH/src/github.com/knqyf263
$ git clone https://github.com/knqyf263/pet.git
$ cd pet
$ make install

Migration

From Keep

https://blog.saltedbrain.org/2018/12/converting-keep-to-pet-snippets.html

Contribute

  1. fork a repository: github.com/knqyf263/pet to github.com/you/repo
  2. get original code: go get github.com/knqyf263/pet
  3. work on original code
  4. add remote to your repo: git remote add myfork https://github.com/you/repo.git
  5. push your changes: git push myfork
  6. create a new Pull Request

License

MIT

Author

Teppei Fukuda

pet's People

Contributors

artdevjs avatar b4b4r07 avatar babarot avatar brumhard avatar cking avatar crpb avatar cxfcxf avatar dependabot[bot] avatar firecat53 avatar glasmasin avatar iambenzo avatar keidarcy avatar knqyf263 avatar matrixx567 avatar onde2rock avatar papanito avatar pbek avatar ramiawar avatar riscie avatar rkmathi avatar ruworuro avatar ryooooooga avatar sadayuki-matsuno avatar shihanng avatar testwill avatar vimsucks avatar wadeg avatar welding-torch avatar widelec-bb avatar yutachaos 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  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

pet's Issues

Type or print the searched command before exec (to edit or else)

First thank you for this very useful tool :)

In a normal situation when searching saved commands i would rather have a look at the command before executing it to either:

  • Edit it
  • Have it on the bash history
  • etc...

Well this can be done with this :
xdotool type "$(pet search)"

I am posting here just to document that and may that could be implemented directly in pet with something like pet exec --print

FR - allow to download gist snippet file

Thank you for pet, I love it and am using it for syncing my ssh connection commands.

I think I had the same issue like #99.

  • added some snippets on one computer (KDE Neon, Ubuntu based, pet installed via deb file)
  • synced them to a gist
  • installed pet on a 2nd computer (Manjaro via yaourt)
  • created new GitHub access token and added gist id of first computer
  • typed pet sync on 2nd computer
  • empty pet-snippet.toml was uploaded pet-snippet.toml was removed in the gist and overwrote snippets from 1st computer

It would be really great to have a pet upload and pet download command to force upload or download.

'version' command prints a wrong version number

When I execute version command with pet version 0.3.4, it prints 0.3.2 as below.

$ wget https://github.com/knqyf263/pet/releases/download/v0.3.4/pet_0.3.4_linux_amd64.tar.gz
$ sha256sum pet_0.3.4_linux_amd64.tar.gz
5f5012b5c90236d3f908a770c2fe6de59ed1c92ac88c35cb99a950a850b8563d  pet_0.3.4_linux_amd64.tar.gz
$ tar xvf pet_0.3.4_linux_amd64.tar.gz
$ ./pet version
pet version 0.3.2

Checksum of a download archive equals to checksum in release page.

I also tried pet_0.3.4_linux_386.tar.gz, pet_0.3.4_windows_386.tar.gz, pet_0.3.4_windows_amd64.tar.gz, and all of these have the same problem.

Suggestion: tags?

It would be nice to have the option of tagging snippets. For instance:

$ pet new 'rabbitmqctl status' --tags rabbitmq
$ pet new 'celery worker -A celery_worker.celery --loglevel=info' --tags celery python flask

And later when searching or listing it would be nice to be able to filter by certain tags.

What do you think?

Suggestion: apt repository

I've noticed that .deb packages are provided for this program already.

An apt repository would allow people to update Debian-based systems automatically.

I found aptirepo, which appears to reatly simplify the process of setting up a simple apt repository. It would appear that all that's required is the hosting of static files from a directory somehow.

Error: sh: 1: vim: not found

Sorry for the double-issue, but I've found a bug!

On my system, I don't have vim installed. To this end, doing pet configure causes an error to be thrown.

I suggest the following behaviour:

  • If the sensible-editor command is installed, use that
  • If the EDITOR environment variable is present, take the editor's binary name from there (e.g. an example value might be EDITOR=nano)

Use environment variables for access tokens

I prefer to not have sensitive passwords in my configuration files. Using environment variables to configure Github and Gitlab would be helpful, because then I can add the config.toml to my public dotfiles repository.

If an access token is blank or missing from the config.toml, the $PET_GITHUB_ACCESS_TOKEN or $PET_GITLAB_ACCESS_TOKEN should be used instead.

escape "<" char from command line

Hello,

Thanks for your work, I installed and tested pet from today only and it seems very promising.

I did not find the way to escape "special" char when adding new command.

Imagine this snippet :

  description = "List RDS snapshots older than <date> from <profile> for <region>"
  command = "aws --profile <profile> rds describe-db-snapshots --region <region> --query 'DBSnapshots[?SnapshotCreateTime<=`<date>`]'"

The problem is that <= starts a new parameter whereas it is part of the command (not a variable like "date").

May be someone know how to escape first < ?

thanks

Can't complete sync configuration because option -u to pet sync doesn't exist anymore

Managed to build pet from source, and now I'm trying to configure syncing, following the instructions here. Got stuck here:

paulo@monk:~/go/src/github.com/knqyf263/pet$ pet sync -u
unknown shorthand flag: 'u' in -u
Usage of sync:
      --config string   config file (default is $HOME/.config/pet/config.toml)
      --debug           debug mode
  -h, --help            help for sync
unknown shorthand flag: 'u' in -u

The only keys I've changed in $HOME/.config/pet/config.toml are selectcmd, which I set to peco, and access_token which I got from https://github.com/settings/tokens/new

sort criteria for `pet exec` respectively `pet search`

Hi there

First of all, I want to provide my deep respect for this project. I think it's a fantastic tool. Very well done 👍 👍
What I wanted to ask is, if there is an easy way to order (sort) the fzf (peco) output of pet execrespectively pet search. I could not find an such option on my look trough the docs and a brief look at the code.
For me personally it would be most intuitive to sort the output alphabetically. (ymmv 😄)

If something like this does not exist I can also offer to create a pr.

Kindly, matthias

Snippet repository

Hi, thanks for this great tool. I was thinking the similar thing before finding it. However I feel a strong need to have a central snippet repository so that we could be more productive and learn cool one liners from community. Is there already some existing? What do you think? 😄

search history is need

it is not very convenient to exec the command I have exec before, I have to set the params again

Truncated default parameter value

I'm new to pet, so maybe I'm missing something, but the following snippet in pet 0.2.3 renders the default value as worl instead of world:

[[snippets]]
  description = "Say hi"
  command = "echo \"Hello, <place=world>\""
  output = ""

Passing in filepath parameters more easily

I think Pet is pretty useful, and love how easy it is to search, share and sync commands via a gist!

All of the commands that I currently use Pet for actually take a filepath as a parameter! This is quite difficult to do at the moment because you cannot auto-complete file paths as you normally can on the shell. This means I often have to copy and paste the filepath - opening a new shell to do this - which is relatively laborious and time-consuming.

I'm not sure how easy it would be to implement auto-complete when entering filenames, but I have an alternative suggestion where pet prints the stored command (leaving in the parameter placeholders), allowing you to copy this into the command-line and edit it to your heart's content. Pet will not execute the command.

This could be used by pet print, pet search --print, or maybe pet exec --print.

cd command not working

Hello.

It's a nice tool.

cd command can not be used.

I tried.

$ pwd
/Users/lion

$ pet list
Description: cd command test
Command: cd ~/hoge/foo/bar
------------------------------

$ pet exec
QUERY>
[cd command test] cd ~/hoge/foo/bar # Enter

$ pwd
/Users/lion # Why?

I expected.

$ pwd
/Users/lion/hoge/foo/bar

Sync Improvement - merge snippets instead of overwrite

Hi.
First of all, congratulations for building this tool I am using it everyday.

I added lots of snippets in the last days, and today I decided to run pet sync in order to synchronize to my snippets gist. But I didn´t specify the -u flag, so it downloaded the contents of the gist file and replaced all my newly created snippets! fortunately I had a backup. I was not aware of this behavior. I think sync should merge the contents of local and remote files and not replacing them like this. The current behavior is more of a backup, than a sync really. It I have pet running of two machines and add snippets In both of then, there is no way to sync automatically without losing data.

Hope this can be improved.

Keep up the good work!

In bash, PREV=$(fc -lrn | head -n 1) doesn't retrieve the previous command

README.md suggests this function to add the last command to pet:

function prev() {
  PREV=$(fc -lrn | head -n 1)
  sh -c "pet new `printf %q "$PREV"`"
}

However, in bash PREV=$(fc -lrn | head -n 1) results in storing PREV=$(fc -lrn | head -n 1) in PREV:

paulo@monk:~$ ls
bash_completion.d  bin  bk  data  default  Desktop  doc  Downloads  foto  gdrive  go  log  Mail  man  PDF  playlist  RCS  src  stage  tmp  watch  xubuntu 17.10.txt
paulo@monk:~$ PREV=$(fc -lrn | head -n 1)
paulo@monk:~$ echo "$PREV"
	 PREV=$(fc -lrn | head -n 1)
paulo@monk:~$ 

To work correctly in bash, that line should be:

PREV=$(fc -ln -1)

as you can see now:

paulo@monk:~$ ls
bash_completion.d  bin  bk  data  default  Desktop  doc  Downloads  foto  gdrive  go  log  Mail  man  PDF  playlist  RCS  src  stage  tmp  watch  xubuntu 17.10.txt
paulo@monk:~$ PREV=$(fc -ln -1)
paulo@monk:~$ echo "$PREV"
	 ls
paulo@monk:~$ 

I'm struggling to get rid of the leading tab, piping the output to sed results in changing the history. If I find out a neat way of doing it, I will document it here.

Separate metadata field for language/syntax

One thing that would be nice for publishing snippets (see #84) is if there was a standard way of indicating which syntax is used, so as to mark the snippet up for syntax highlighting. It can already be achieved by tags, but that would require some sort of convention for which tag is representing syntax as opposed to e.g. the tool used or any other tag.

I don’t know if you can make sense of what I wrote, but for example for an awk one liner, I would want to mark it for “sh” syntax highlighting but maybe also tag it “awk”.

If this is out of scope for the project it is easily achieved with some sort of tag prefix/suffix, though any third party scripts relying on this would need to be customized to match each users convention. I guess that doesn’t matter if I’m the only one who would like to publish/share my snippets this way ...

pet-snippet.toml is empty

New install pet, and sync gist prompts are as follows

pet-snippet.toml is empty

v0.3.4

There is also a case of overwriting the gist record, resulting in a missing code snippet

More than one line in description field?

I love the tool, i really think it is awesome. A quick enhancement request:

Is it possible to extend the description field to include new lines? so that I can include examples of what actually command is doing by supplying an output of a command that contains more than one line?

For example here is a command:
awk -F'|' '{print $2,$3,$5,$6}' myfile.txt | awk '{$1=$1};1' | awk NF

and the output
order1 requested shipped 12/12/12
order2 requested halted 12/12/12
....

how can I include an output like above in the description field?

Interactive shell reads fail when using placeholders

Executing openssl aes-256-cbc -a -salt -in test.csv -out test.csv.enc requires typing the password twice.

Entering the command by hand in the terminal and then typing the password twice works.

Saving the command exactly this way to pet and then typing the password twice works.

Saving the command with a <placeholder> for the filename and executing it, will create the same command. But typing the password the first time will fail when hitting enter and the password will be printed in the next $ shell line.

Seems that when using placeholders, the characters are not reaching the std input of openssl. Executing the command manually again, will also fail from then on with the same error.

Version 3.2.0 on macOS Sierra 10.12.

image

fzf support

Hello, it will be great to add support for fzf. It's more popular than peko.

pet search [flags] <string> to query with an initial value (without option -q/--query)

As a suggestion, I believe it's a more natural syntax, like grep for instance, for searching a snippet, to use the first argument after the options as the initial search string, like this:

pet search [other-flags] <string>

instead of, currently:

pet search [other-flags] --query <string>

If there's a string after all options have been processed, it's natural to expect it to be the search string.

So, if I wanted to search for copy, the command would be:

pet search copy

It feels more natural to me, more alike any other search command, such as grep and locate. The option --query feels unnecessary in this context.

is there an include/source feature?

can I have my pet snippet to include another pet snippet and have both available to pet search?
use case: I have some private commands that I sync across multiple machines. in addition to that, I also have some more commands for my work use only and would like clear separation between these two sets. from time to time, I make changes to both sets. my current solution is to sync the two pet snippet files to have the work pet snippet to pick up missing items from private pet snippet. ideally I would like my work pet snippet automatically picks up everything from my private pet snippet. the way I envision this to work is to have my work pet snippet to include the private pet snippet, i.e., an include or source feature. makes sense?

doesn't compile

go get github.com/knqyf263/pet

go/src/github.com/knqyf263/pet/cmd/sync.go:73: too many arguments in call to client.Gists.Create
go/src/github.com/knqyf263/pet/cmd/sync.go:77: retGist.GetID undefined (type *github.Gist has no field or method GetID)
go/src/github.com/knqyf263/pet/cmd/sync.go:79: too many arguments in call to client.Gists.Edit
go/src/github.com/knqyf263/pet/cmd/sync.go:94: too many arguments in call to client.Gists.Get

Dialog inputs bug and an improvement

Dialog inputs for parameter variables is absolutely awesome, however I detected one bug and one possible improvement:

Bug:

  • when text is long often extra whitespaces are entered between lines

Improvement:

  • input param dialogs could be as long as search command (top window)

Can't build from source: missing commands dep and vet

I've discovered pet from this article, and I'm trying to build it from source. I cloned the git repository and ran make, but commands dep and vet are missing.

My environment is Xubuntu 17.10. I searched for dep and vet in the Ubuntu repositories and didn't find them. Where do I install them from ?

sh: peco: command not found

in CentOS7 and go version 1.8

install pet with go get github.com/knqyf263/pet

when i use pet edit and pet list it work good, but when use pet exec it report error: sh: peco: command not found

thx for eht aswsome tool

Placeholders do not behave well

image
As you can see from the screenshot provided, both param values are missing the last character...
This was not an issue before, as I recall.

panic: runtime error SIGSEGV during sync command

$ pet --debug sync
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x136cb94]

goroutine 1 [running]:
github.com/knqyf263/pet/cmd.download(0x145bdc7, 0xb)
	/Users/teppei/src/github.com/knqyf263/pet/cmd/sync.go:101 +0x1c4
github.com/knqyf263/pet/cmd.sync(0x165f160, 0xc4200153c0, 0x0, 0x1, 0x0, 0x0)
	/Users/teppei/src/github.com/knqyf263/pet/cmd/sync.go:34 +0x5f
github.com/spf13/cobra.(*Command).execute(0x165f160, 0xc420015350, 0x1, 0x1, 0x165f160, 0xc420015350)
	/Users/teppei/src/github.com/spf13/cobra/command.go:644 +0x3ef
github.com/spf13/cobra.(*Command).ExecuteC(0x165eb00, 0xc42001e0b8, 0x0, 0x1661c28)
	/Users/teppei/src/github.com/spf13/cobra/command.go:734 +0x339
github.com/spf13/cobra.(*Command).Execute(0x165eb00, 0x1, 0x0)
	/Users/teppei/src/github.com/spf13/cobra/command.go:693 +0x2b
github.com/knqyf263/pet/cmd.Execute()
	/Users/teppei/src/github.com/knqyf263/pet/cmd/root.go:47 +0x31
main.main()
	/Users/teppei/src/github.com/knqyf263/pet/main.go:20 +0x20

Print the command itself before `pet exec`?

RT. Are there some ways to do this?

I use pet to save some long commands with placeholder replacement, once it executed via pet exec, I couldn't reveal what the final command text, it's so appreciated that pet could echo the command with the plain text before executing.

Will it support for this? Thanks!

"invalid argument" when the chosen snippet includes <param> on WSL

On Microsoft Windows [Version 10.0.15063]'s WSL

$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 16.04.2 LTS
Release:        16.04
Codename:       xenial
$ pet version
pet version 0.2.2 (was extracted from downloaded .zip file)
$ cat .config/pet/config.toml
[General]
  snippetfile = "/home/taketori/.config/pet/snippet.toml"
  editor = "micro"
  column = 40
  selectcmd = "fzf"

[Gist]
  file_name = "pet-snippet.toml"
  access_token = ""
  gist_id = ""
  public = false
$ pet list
Description: test1
    Command: echo <param=aaa>
------------------------------
Description: test2
    Command: echo <param>
------------------------------
Description: test3
    Command: echo aaa
------------------------------

both test1 and test2 show error like below:
(test3 does not.)

$ pet exec
2017/05/05 23:59:49 invalid argument
panic: invalid argument


goroutine 1 [running]:
log.Panicln(0xc42003d830, 0x1, 0x1)
        /usr/local/Cellar/go/1.8/libexec/src/log/log.go:336 +0xc0
github.com/knqyf263/pet/dialog.GenerateParamsLayout(0xc42001c150, 0xc420095af0, 0xc)
        /Users/teppei/src/github.com/knqyf263/pet/dialog/view.go:36 +0xac
github.com/knqyf263/pet/cmd.filter(0x0, 0x0, 0x0, 0xc420092f90, 0x26, 0x0, 0x0, 0x0)
        /Users/teppei/src/github.com/knqyf263/pet/cmd/util.go:76 +0xcc2
github.com/knqyf263/pet/cmd.execute(0xabc620, 0xadd008, 0x0, 0x0, 0x0, 0x0)
        /Users/teppei/src/github.com/knqyf263/pet/cmd/exec.go:28 +0x7c
github.com/knqyf263/pet/vendor/github.com/spf13/cobra.(*Command).execute(0xabc620, 0xadd008, 0x0, 0x0, 0xabc620, 0xadd008)
        /Users/teppei/src/github.com/knqyf263/pet/vendor/github.com/spf13/cobra/command.go:644 +0x3f2
github.com/knqyf263/pet/vendor/github.com/spf13/cobra.(*Command).ExecuteC(0xabcc80, 0xc42006c058, 0x0, 0xac0468)
        /Users/teppei/src/github.com/knqyf263/pet/vendor/github.com/spf13/cobra/command.go:734 +0x339
github.com/knqyf263/pet/vendor/github.com/spf13/cobra.(*Command).Execute(0xabcc80, 0x1, 0x0)
        /Users/teppei/src/github.com/knqyf263/pet/vendor/github.com/spf13/cobra/command.go:693 +0x2b
github.com/knqyf263/pet/cmd.Execute()
        /Users/teppei/src/github.com/knqyf263/pet/cmd/root.go:47 +0x31
main.main()
        /Users/teppei/src/github.com/knqyf263/pet/main.go:20 +0x20

Option to output all metadata from search?

Would it be possible to allow for optional output of the complete metadata in a structured format for the selected snippets after searching? (Personally I would prefer JSON for interoperability, but I guess TOML would be more in line with the project.)

I've just recently found and tried your tool and find it really nice to use. Besides a fast and nice fuzzy search, one thing I was hoping for when I started searching for a snippet manager was the ability to easily share snippets as nicely formatted markdown. The Gist-sync in pet is certainly useful, but maybe not for publishing.

If I could get complete output from search in a structured format, I could use pet in a pipeline where I implement the formatting myself.

Error in Readme

Was getting start with pet. In the readme it says

image
Command and Description are the wrong way round, are they?

For Frodo!

Improvement - pet search - Does not write in current line

When I need to modify the pet store command I use search instead of exec.
In this case, I need copy paste pet search result.
We can improve search command which put after current terminal pointer. like fzf command do when we use Ctrl + R for search history.
This improvement need in the search command.

All configured authentication methods failed

Use a password to connect and reconnect after the connection is disconnected.

Connecting to 52.81.25.47
SHA256 fingerprint: 84ff095e775352b6b4076523704dfe73a065bbda15026b4825d2929c336b0935
Trying saved password....
All configured authentication methods failed

Reconnect again, prompt for password, you can connect normally.

best way to multilined command ?

Is there a example to use multiple lined command in pet ?
seems below style is not works as expected

command = """
echo a
echo b
echo c
"""

Does not work when username contains spaces

Might be a Windows-specific problem. I have a space in my username (error made in my early days :-)), and pet commands are failing.

λ pet edit
'C:\Users\Joker' 不是内部或外部命令,也不是可运行的程序或批处理文件。
Error: exit status 1
Usage:
  pet edit [flags]

Global Flags:
      --config string   config file (default is $HOME/.config/pet/config.toml)
      --debug           debug mode

exit status 1

The first line in English:

'C:\Users\Joker' is neither an internal or external command, nor an executable or batch file.

My home directory is C:\Users\Joker Qyou. Windows 10 anniversary x64, pet v0.2.0 x64 binary downloaded from release page.

cd to a path

I often go to a relativ deep path. So I added

------------------------------
Description: Go to folder
Command: cd src/main/java/path/to/my/folder

but when I run pet exec that command is just ignored. No error no change of directory.

pet version
pet version 0.2.1

Go back one char

Hi,

thanks for this neat tool.
I am using bash on Ubuntu 16.04 64 bit.

When I am using pet new and try to go back one char with left arrow it looks like this:

Command: unzip^[[D

Has the ^[[D to do with bash?

For Frodo

Variables via input dialog

Thank you for this awesome project, I have an idea to extend the project with ability to pass variables. There could be some integration (dialog) that would ask a user with what variable values he/she wants to execute a command.

Let's take an example of removing a branch in git locally and remotely I often do:

git branch -D <branch_name> && git push --delete origin <branch_name>

such command could open a popup (dialog) where I could enter branch_name and then command would fill up the variables and execute the chained set of commands.

What do you think?

Can't install

I'm using ZSH and brew, I've used your (awesome) script for a really long time

Yesterday I updated via brew and it kept saying something about not being able to find the zsh autocompletions folder (it worked with ZSH before)

Then today I go to update to see if there's a patch, and now it says this:

Error: pet: /usr/local/Homebrew/Library/Taps/knqyf263/homebrew-pet/pet.rb:6: syntax error, unexpected <<, expecting keyword_end
<<<<<<< HEAD
  ^
/usr/local/Homebrew/Library/Taps/knqyf263/homebrew-pet/pet.rb:8: syntax error, unexpected ===, expecting keyword_end
=======
   ^
/usr/local/Homebrew/Library/Taps/knqyf263/homebrew-pet/pet.rb:10: syntax error, unexpected >>, expecting keyword_end
>>>>>>> pet version v0.2.4
  ^
/usr/local/Homebrew/Library/Taps/knqyf263/homebrew-pet/pet.rb:10: no .<digit> floating literal anymore; put 0 before dot
>>>>>>> pet version v0.2.4
                       ^
/usr/local/Homebrew/Library/Taps/knqyf263/homebrew-pet/pet.rb:10: syntax error, unexpected tFLOAT, expecting '('
~ »

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.