{"id":15583740,"url":"https://github.com/mehran-prs/snip","last_synced_at":"2025-04-03T03:12:59.285Z","repository":{"id":241001559,"uuid":"797841872","full_name":"mehran-prs/snip","owner":"mehran-prs","description":"A simple and minimal command-line snippet manager","archived":false,"fork":false,"pushed_at":"2025-02-11T08:53:28.000Z","size":6931,"stargazers_count":74,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-03-26T22:09:21.368Z","etag":null,"topics":["command-line","console","developer-tools","documentation","go","golang","linux","macos","osx","shell","snip","snippet-manager","snippets","terminal","tools"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mehran-prs.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-05-08T16:13:06.000Z","updated_at":"2025-03-08T14:50:00.000Z","dependencies_parsed_at":"2024-05-21T22:22:49.834Z","dependency_job_id":"4d327327-821e-4303-90da-d01474fcfffd","html_url":"https://github.com/mehran-prs/snip","commit_stats":{"total_commits":24,"total_committers":1,"mean_commits":24.0,"dds":0.0,"last_synced_commit":"f2b58e4d08cbd164aa9469b44d14ecaf857b316e"},"previous_names":["mehran-prs/snip"],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mehran-prs%2Fsnip","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mehran-prs%2Fsnip/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mehran-prs%2Fsnip/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mehran-prs%2Fsnip/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mehran-prs","download_url":"https://codeload.github.com/mehran-prs/snip/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246927839,"owners_count":20856198,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["command-line","console","developer-tools","documentation","go","golang","linux","macos","osx","shell","snip","snippet-manager","snippets","terminal","tools"],"created_at":"2024-10-02T20:20:53.911Z","updated_at":"2025-04-03T03:12:59.250Z","avatar_url":"https://github.com/mehran-prs.png","language":"Go","funding_links":[],"categories":["\u003ca name=\"cheatsheet\"\u003e\u003c/a\u003eCommands cheatsheet and snippets"],"sub_categories":[],"readme":"\u003cp align=\"center\"\u003e\n\u003cimg width=\"250\" src=\"./docs/images/snip_logo.png\"  alt=\"snip logo\"/\u003e\n\u003c/p\u003e\n\n\u003cp align=\"center\"\u003e\n  \u003ca href=\"https://goreportcard.com/report/github.com/mehran-prs/snip\"\u003e\n    \u003cimg src=\"https://goreportcard.com/badge/github.com/mehran-prs/snip\"\u003e\n  \u003c/a\u003e\n  \u003ca href=\"https://godoc.org/github.com/mehran-prs/snip\"\u003e\n    \u003cimg src=\"https://godoc.org/github.com/mehran-prs/snip?status.svg\" alt=\"GoDoc\"\u003e\n  \u003c/a\u003e\n  \u003ca href=\"https://codecov.io/gh/mehran-prs/snip\"\u003e\n    \u003cimg src=\"https://codecov.io/gh/mehran-prs/snip/branch/main/graph/badge.svg\" /\u003e\n  \u003c/a\u003e\n\u003c/p\u003e\n\n\nSnip is a simple and minimal command-line snippet manager.\n\n### Features\n\n- View your snippets on command line and also manage them (create, edit, delete) using your favorite editor.\n- Command-line auto-completion for the snippets names (supports `bash`, `zsh`, `fish` and `powershell`).\n- Seamlessly integration with `fzf` to provide fuzzy completion(currently supports `zsh` shell).\n- Syntax highlighting and Git integration\n\n### How to use\n\n#### View a snippet\n\n- Run `snip {snippet_name}` to view a snippet.\n- If you've\n  enabled [`fzf` shell integration](https://github.com/junegunn/fzf?tab=readme-ov-file#setting-up-shell-integration) in\n  you `zsh` shell, you can find snippets by fuzzy completion. e.g., type `snip **` and press tab.\n\n![snip view snippets](docs/images/snip-view.gif)\n\n#### Edit snippets (Create|Update|Delete)\n\n- Run `snip edit` to open your snippets repository in your favorite editor.\n- Run `snip edit {snippet_path}` to create|edit your snippet in your favorite editor.\n- Run `snip rm {snippet_path}` to remove a snippet. (use `-r` flag to remove recursively)\n\n![snip edit snippets](docs/images/snip-edit.gif)\n\n### Sync snippets changes with your remote git repository\n\n- Run `snip sync [optional commit message]` to pull and then push your snippets changes. This command runs the following\n  commands:\n\n```bash\ngit pull origin\ngit add -A\ngit commit -m \"{your_provided_message | default_message}\"\ngit push origin\n```\n\n![snip sync snippets](docs/images/snip-sync.gif)\n\n\u003e [!NOTE]\n\u003e before running `git sync` for first time, you need to initialize git in your snippets directory and\n\u003e also set upstream of your default branch. something like the following commands:\n\n```bash\ncd $(snip dir)\ngit init\ngit remote add origin  {your_repo_remote_path}\n# Push your first commit to setup upstream branch\ngit add -A \u0026\u0026 git commit -m \"Initial commit\"\ngit push -u origin main\n```\n\n### Getting started\n\n- [Install the snip command](#installation).\n- [Enable auto-completion](#shell-integration)\n- (optional) Set custom [snippets directory path](#customization).\n- (optional) [Enable syntax highlighting](#enable-syntax-highlighting) (recommended)\n- (optional) [Enable fuzzy completion](#enable-fuzzy-completion) if your shell is `zsh` (recommended).\n- [Use `snip`](#how-to-use) :))\n\n### Installation\n\nInstall using go:\n\n```bash\ngo install -ldflags \"-X main.Version=main -X main.Date=`date +'%FT%TZ%z'`\"  github.com/mehran-prs/snip@main\n```\n\nOr get pre-compiled executables [here](http://github.com/mehran-prs/snip/releases)\n\n\u003e [!IMPORTANT]\n\u003e To set up completion, see the [instructions below](#shell-integration).\n\n### Shell integration\n\nAdd the following line to your shell configuration file.\n\n* bash\n  ```sh\n  # Set up snip completion\n  source \u003c(snip completion bash)\n  ```\n* zsh\n  ```sh\n  # Set up snip completion (including fuzzy completion)\n  source \u003c(snip completion zsh)\n  ```\n* fish\n  ```fish\n  # Set up snip completion\n  snip completion fish | source\n  ```\n\n\u003e [!NOTE]\n\u003e [fzf shell integration](https://github.com/junegunn/fzf?tab=readme-ov-file#setting-up-shell-integration) is a\n\u003e pre-requisite of snip fuzzy completion.\n\n### Customization\n\nSet the following env variables to customize snip(e.g., put `export SNIP_DIR=/path/to/dir` in your shell config file):\n\n| Name                     | Default                                             | Description                                                                     |\n|--------------------------|-----------------------------------------------------|---------------------------------------------------------------------------------|\n| SNIP_DIR                 | `~/snippets`                                        | The snippets directory. It must be absolute path                                |\n| SNIP_FILE_VIEWER_CMD     | `cat`                                               | The tool which renders non-markdown files in cmd                                |\n| SNIP_MARKDOWN_VIEWER_CMD | `cat`                                               | The tool which renders markdown files in cmd                                    |\n| SNIP_EDITOR              | Value of the `EDITOR` env variable, otherwise `vim` | The editor which snip uses to let you edit snippets                             |\n| SNIP_GIT                 | `git`                                               | The git command which it uses to sync snippets with your remote git repository  |\n| SNIP_EXCLUDE             | `.git,.idea`                                        | comma-separated list of directories that you want to exclude in auto-completion |\n| SNIP_VERBOSE             | \"\"                                                  | Enable verbose mode (values: `true`)                                            |\n| SNIP_LOG_TMP_FILENAME    | \"\"                                                  | Set path to a temporary log file. it's helpful in autocompletion debugging      |\n\n### Commands\n\n```bash\nUsage:\n  snip [command] [flags]\n  snip [command]\n\nAvailable Commands:\n  completion  Generate completion script\n  dir         prints the snippets directory\n  edit        Create|Edit the snippet in the editor\n  help        Help about any command\n  rm          Remove a snippet or directory\n  sync        sync the snippets changes with your remote git repository\n  version     Print the version and build information\n\nFlags:\n  -h, --help   help for snip\n```\n\n### Enable syntax highlighting\n\n- Install [`bat`](https://github.com/sharkdp/bat) and [`glow`](https://github.com/charmbracelet/glow).\n\n- Set the following env variables in your shell configuration(e.g., `~/.zshrc`):\n\n```bash\nexport SNIP_FILE_VIEWER_CMD=\"bat --style plain --paging never\"\nexport SNIP_MARKDOWN_VIEWER_CMD=\"glow\"\n```\n\n\u003e [!IMPORTANT]\n\u003e On some operating systems (like ubuntu), the `bat` executable may be installed as `batcat` instead of `bat`, in such\n\u003e cases, set `batcat` instead of `bat` in `SNIP_FILE_VIEWER_CMD` env variable.\n\n### Enable fuzzy completion\n\n\u003e [!Note]\n\u003e Currently fuzzy completion is supported just in zsh.\n\n- Install [`fzf`](https://github.com/junegunn/fzf) to enable fuzzy completion.\n- Set up [`fzf` shell integration](https://github.com/junegunn/fzf?tab=readme-ov-file#setting-up-shell-integration)\n\n### Multi-tenancy (Advanced usage)\n\nI like to have multiple instances of the `snip` command under different names for multiple repositories. for example\n`snip` to manage my snippets, and `tasks` to manage my tasks.\nWe can do that by creating a soft-link to the `snip` command (other solutions like aliasing doesn't work\nperfectly in auto-completion, at least for me :)) ),\nfor example to add the `tasks` command, follow these steps:\n\n- Link `tasks` to the `snip` command:\n\n```bash \nln -s $(whereis snip | awk '{print $2}') /usr/local/bin/tasks\n```\n\n- Update your shell config to set the tasks directory for the `tasks` command(as its snippets directory) and also\n  enable autocompletion for it:\n\n```bash\n# Set the tasks directory (change to your own tasks directory)\nexport TASKS_DIR=/path/to/my/tasks\n\n# Enable shell auto-completion (in this example, enabled for zsh)\nsource \u003c(tasks completion zsh)\n\n```\n\n\u003e [!NOTE]\n\u003e You may wonder how the `tasks` command reads its directory path from `TASKS_DIR` env variable instead of `SNIP_DIR`,\n\u003e actually the `snip` tool reads env variables from `{APPNAME}_{ENV_NAME}` (in this case `TASKS_*`) and if\n\u003e it was empty then reads from `SNIP_{ENV_NAME}`.\n\n## Contributing\n\n1. Fork the repository\n1. Clone your fork (`git clone https://github.com/\u003cyour_username\u003e/snip \u0026\u0026 cd snip`)\n1. Create your feature branch (`git checkout -b my-new-feature`)\n1. Make changes and add them (`git add .`)\n1. Commit your changes (`git commit -m 'Add some feature'`)\n1. Push to the branch (`git push -u origin my-new-feature`)\n1. Create new pull request\n\n### Some helper commands for contributors\n\n```bash\n# Run tests\ngo test ./...\n\n# Test coverage\ngo test -coverprofile cover.out ./...\ngo tool cover -html cover.out # view as html\ngo tool cover -func cover.out # output coverage per functions\n\n# Run linters\ngo install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.58.1\ngolangci-lint run ./...\n\n# build\ngo build -o snip .\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmehran-prs%2Fsnip","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmehran-prs%2Fsnip","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmehran-prs%2Fsnip/lists"}