Giter VIP home page Giter VIP logo

snap's Introduction

Workflow status

cheat

cheat allows you to create and view interactive cheatsheets on the command-line. It was designed to help remind *nix system administrators of options for commands that they use frequently, but not frequently enough to remember.

The obligatory xkcd

Use cheat with cheatsheets.

Example

The next time you're forced to disarm a nuclear weapon without consulting Google, you may run:

cheat tar

You will be presented with a cheatsheet resembling the following:

# To extract an uncompressed archive:
tar -xvf '/path/to/foo.tar'

# To extract a .gz archive:
tar -xzvf '/path/to/foo.tgz'

# To create a .gz archive:
tar -czvf '/path/to/foo.tgz' '/path/to/foo/'

# To extract a .bz2 archive:
tar -xjvf '/path/to/foo.tgz'

# To create a .bz2 archive:
tar -cjvf '/path/to/foo.tgz' '/path/to/foo/'

Usage

To view a cheatsheet:

cheat tar      # a "top-level" cheatsheet
cheat foo/bar  # a "nested" cheatsheet

To edit a cheatsheet:

cheat -e tar     # opens the "tar" cheatsheet for editing, or creates it if it does not exist
cheat -e foo/bar # nested cheatsheets are accessed like this

To view the configured cheatpaths:

cheat -d

To list all available cheatsheets:

cheat -l

To list all cheatsheets that are tagged with "networking":

cheat -l -t networking

To list all cheatsheets on the "personal" path:

cheat -l -p personal

To search for the phrase "ssh" among cheatsheets:

cheat -s ssh

To search (by regex) for cheatsheets that contain an IP address:

cheat -r -s '(?:[0-9]{1,3}\.){3}[0-9]{1,3}'

Flags may be combined in intuitive ways. Example: to search sheets on the "personal" cheatpath that are tagged with "networking" and match a regex:

cheat -p personal -t networking --regex -s '(?:[0-9]{1,3}\.){3}[0-9]{1,3}'

Installing

For installation and configuration instructions, see INSTALLING.md.

Cheatsheets

Cheatsheets are plain-text files with no file extension, and are named according to the command used to view them:

cheat tar     # file is named "tar"
cheat foo/bar # file is named "bar", in a "foo" subdirectory

Cheatsheet text may optionally be preceeded by a YAML frontmatter header that assigns tags and specifies syntax:

---
syntax: javascript
tags: [ array, map ]
---
// To map over an array:
const squares = [1, 2, 3, 4].map(x => x * x);

The cheat executable includes no cheatsheets, but community-sourced cheatsheets are available. You will be asked if you would like to install the community-sourced cheatsheets the first time you run cheat.

Cheatpaths

Cheatsheets are stored on "cheatpaths", which are directories that contain cheatsheets. Cheatpaths are specified in the conf.yml file.

It can be useful to configure cheat against multiple cheatpaths. A common pattern is to store cheatsheets from multiple repositories on individual cheatpaths:

# conf.yml:
# ...
cheatpaths:
  - name: community                   # a name for the cheatpath
    path: ~/documents/cheat/community # the path's location on the filesystem
    tags: [ community ]               # these tags will be applied to all sheets on the path
    readonly: true                    # if true, `cheat` will not create new cheatsheets here

  - name: personal
    path: ~/documents/cheat/personal  # this is a separate directory and repository than above
    tags: [ personal ]
    readonly: false                   # new sheets may be written here
# ...

The readonly option instructs cheat not to edit (or create) any cheatsheets on the path. This is useful to prevent merge-conflicts from arising on upstream cheatsheet repositories.

If a user attempts to edit a cheatsheet on a read-only cheatpath, cheat will transparently copy that sheet to a writeable directory before opening it for editing.

Directory-scoped Cheatpaths

At times, it can be useful to closely associate cheatsheets with a directory on your filesystem. cheat facilitates this by searching for a .cheat folder in the current working directory. If found, the .cheat directory will (temporarily) be added to the cheatpaths.

Autocompletion

Shell autocompletion is currently available for bash, fish, and zsh. Copy the relevant completion script into the appropriate directory on your filesystem to enable autocompletion. (This directory will vary depending on operating system and shell specifics.)

Additionally, cheat supports enhanced autocompletion via integration with fzf. To enable fzf integration:

  1. Ensure that fzf is available on your $PATH
  2. Set an envvar: export CHEAT_USE_FZF=true

snap's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

snap's Issues

Missing config options in cheat break snap install

Hi @chrisallenlane, I face an issue with building the latest cheat version.

Issue description

cheat version 4.3.0 does not work with snap.

~ » cheat tar                                                                                                                                                                                                             
panic: interface conversion: interface {} is nil, not bool

goroutine 1 [running]:
main.main()
	github.com/cheat/cheat/cmd/cheat/main.go:123 +0xa45

Seems to me the snap version is missing some config options? Do you have an idea how best to solve this?
Problem seems to come from this:
https://github.com/cheat/cheat/blob/master/cmd/cheat/main.go#L123

Reproduce

sudo snap install cheat --beta
cheat -v                                                                                                                                                                                                            
**4.3.3**
cheat tar 

Best
Michael

Can't download community cheatsheet

→ cheat find
A config file was not found. Would you like to create one now? [Y/n]:
Would you like to download the community cheatsheets? [Y/n]:
Cloning into '/home/jazzabeanie/snap/cheat/common/.config/cheat/cheatsheets/community'...
fatal: remote error:
  The unauthenticated git protocol on port 9418 is no longer supported.
Please see https://github.blog/2021-09-01-improving-git-protocol-security-github/ for more information.
failed to run installer: failed to clone cheatsheets: failed to clone cheatsheets: exit status 128

I solved the issue by manually creating the directory and cloning the repo. Then it complained about a personal directory, which I created and now it's working. Would be nice for new users if this worked.

Rebase snap on new go version

Hi @chrisallenlane,

I rebased and build and released the snap version on cheat 3.2.1.
To get the build working for all architectures I used peaces of your shellscript.

I tested the amd64 and arm64 version and it looks fine to me.

One thing which is not so nice currently - if the personal cheatpath is not given one get's in the errormessage:

$ cheat
failed to load config: failed to resolve symlink: , lstat /home/ubuntu/snap/cheat/1300/.cheat: no such file or directory

Would it not be more convinient to tell the user to create this directory by providing the command in the message?
This /home/ubuntu/snap/cheat/1300/ is the Snap's view on the user's cheat home dir. The symlink is this: /home/ubuntu/snap/cheat/current/ and current is a symlink to the snap version 1300.

In the same direction goes this: I think it would be nice to give the user a clear message when initially no editor is set:

$ cheat
failed to load config: no editor set

would be more convinient with something like this:
failed to load config: $EDITOR or $VISUAL not set. Please configure environment variable.

What do you think about this?

Greetings
Michael

Cheat not working from home directory

I'm using the ZSH shell on Kubuntu 18.04.
After installing the cheat snap I run cheat.cheatsheet-setup and it just returns to the terminal prompt.
I expected some sort of setup procedure, but that may be done without input.

Running the cheat command at this point if in the ~/ directory returns the error

failed to list cheatsheets: failed to load cheatsheets: error walking path: open /home/nomad/.cheat: permission denied

However if I make, apparently, any other folder on the system the working directory, cheat works fine.
I've ran it from several directories inside the ~/ directory and in the / directory.

The folder ~/.cheat exists and is owned by me, but is empty.
The only odd thing I see about the .cheat folder is the date. It was created today, but it shows it
was created a year ago.

drwxrwxr-x 2 nomad nomad 4.0K Feb 21 2019 .cheat

failed to edit cheatsheet: fork/exec /usr/bin/editor: permission denied

A description of the problem
I am using Ubuntu 22.04 and just installed cheat via snap. Upon trying to edit a cheatsheet, I get the following error:

foo@asdf:~$ cheat -e yt-dlp
failed to edit cheatsheet: fork/exec /usr/bin/editor: permission denied

I am semi-sure this is caused by snap restricting the rights of the packages it installs. I do not have the error above when using the downloaded binaries

cheat version info

foo@asdf:~$ cheat -v
4.4.0

conf.yml not found

I installed cheat via snap, but cheat wouldn't recognize a conf.yml in any directory except /snap, which seems to be read-only. The directories I tried include ~/.config/cheat/conf.yml, /etc/cheat/conf.yml, and ~/snap/cheat/1558/.cheat/conf.yml. I ended up downloading the executable.

Add Snap package Interface so it can use XDG .config/cheat/conf.yml location

Is your feature request related to a problem? Please describe.
It isn't currently possible to use the Snap package with the standard conf.yml file location:

$ export CHEAT_CONFIG_PATH=~/.config/cheat/conf.yml
$ cheat init
failed to load config: could not read config file: open /home/finchd/.config/cheat/conf.yml: permission denied

This is a security feature of snaps, that they can't access the user homedir.
Instead the config (and community cheatsheets) are installed to: ~/snap/cheat/common/.config/cheat/conf.yml
Which is difficult to find later, difficult to include in a dotfiles repo, etc

Describe the solution you'd like
Similar to lucagrulla/cw, use a Snap Interface. With cw, you can run sudo snap connect cw-sh:dot-aws-config-credentials after installing the snap, to give it access to ~/.aws/credentials for each snap user.

A Snap Interface for cheat could be called 'dot-cheat-config' and give the package access to reach ~/.config/cheat/* to store cheatsheets and the conf.yml in.

Describe alternatives you've considered
Running cheat init without exporting CHEAT_CONFIG_PATH and letting it write to ~/snap/cheat/ works, and does echo out the location of the new conf.yml so the user can find the config the first time.
This isn't a major showstopper by any means, but seems like a reasonable packaging addition.

Additional context

Version Info:

$ cheat -v
3.8.0
$ snap --version
snap 2.44.2+20.04
snapd 2.44.2+20.04
series 16
ubuntu 20.04
kernel 5.4.0-21-generic

Unclear first run/configuration steps

I am trying to install cheat on Ubuntu 20.10, but I am stuck at the following situation:

~$ cheat
A config file was not found. Would you like to create one now? [Y/n]:
Would you like to download the community cheatsheets? [Y/n]:
warning: unable to access '/etc/gitconfig': Permission denied
warning: unable to access '/etc/gitconfig': Permission denied
fatal: unknown error occurred while reading the configuration files
failed to create config: failed to clone cheatsheets: exit status 128

And I get the same with sudo.

The README.md states:

$ snap install cheat
$ cheat.cheatsheet-setup

However, cheat.cheatsheet-setup is not found on my Ubuntu 20.10 and I don't understand where it should come from. Should it be included in the snap package?

I am really confused on how I should configure/run cheat for the first time. I expected that snap install cheat automatically installs also the default cheatsheets and configures cheat, but maybe I am doing something wrong.

Probably related (regarding the reasons behind this issue): #6

(btw, thanks a lot for making this amazing tool, it is very helpful! 🍺)

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.