From 4d7179741648ccae94617f34cb07e17a82b16253 Mon Sep 17 00:00:00 2001 From: Uriah Galang Date: Tue, 19 Dec 2023 17:58:01 +0800 Subject: [PATCH] snip-cli (#4) * snip-cli * fix path --- .github/workflows/release.yml | 2 +- Cargo.lock | 4 +- Cargo.toml | 26 +++++++--- README.md | 98 ++++++++++++----------------------- provision.sh | 4 +- scripts/postinstall | 2 +- src/main.rs | 28 +++++----- 7 files changed, 72 insertions(+), 92 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 3ba5b46..63b2fe9 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -43,7 +43,7 @@ jobs: with: # (required) Comma-separated list of binary names (non-extension portion of filename) to build and upload. # Note that glob pattern is not supported yet. - bin: snipr + bin: snip # (optional) Target triple, default is host triple. target: ${{ matrix.target }} # (required) GitHub token for uploading assets to GitHub Releases. diff --git a/Cargo.lock b/Cargo.lock index 8268982..c683c20 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -583,8 +583,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4dccd0940a2dcdf68d092b8cbab7dc0ad8fa938bf95787e1b916b0e3d0e8e970" [[package]] -name = "snipr" -version = "0.1.0" +name = "snip-cli" +version = "0.1.1" dependencies = [ "anyhow", "clap 4.4.11", diff --git a/Cargo.toml b/Cargo.toml index fa9a79b..cd529ad 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,13 +1,25 @@ [package] -name = "snipr" -version = "0.1.0" +name = "snip-cli" +version = "0.1.1" edition = "2021" authors = ["Uriah G. "] -description = "A CLI tool (snipr) for managing Neovim and VSCode snippets" +description = "A CLI tool (snip-cli) for managing Neovim and VSCode snippets" readme = "README.md" license = "MIT" keywords = ["neovim", "snippets", "rust", "cli", "vscode"] categories = ["command-line-utilities"] + +# use in Github workflow `release` +[[bin]] +name = "snip" +path = "src/main.rs" + +# Used when Bunding for OSX +[[bin]] +name = "snip-cli" +path = "src/main.rs" + + # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] @@ -22,15 +34,15 @@ dirs-next = "2.0.0" dotenv = { version = "0.15.0", features = ["clap"] } [package.metadata.bundle] -name = "snipr" # The name of your application -identifier = "com.codeitlikemiley.snipr" # The bundle identifier of your application +name = "snip" # The name of your application +identifier = "com.codeitlikemiley.snip" # The bundle identifier of your application copyright = "Copyright (c) codeitlikemiley 2023. All rights reserved." category = "Developer Tool" short_description = "A CLI tool for managing Neovim and VSCode snippets" long_description = "A CLI tool for managing Neovim and VSCode snippets" -version = "0.1.0" # Version of your application +version = "0.1.1" # Version of your application osx_url_schemes = [ - "com.codeitlikemiley.snipr", + "com.codeitlikemiley.snip", ] # URL schemes your application supports script = "scripts/postinstall" # Path to your postinstall script diff --git a/README.md b/README.md index f954299..55f62d6 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,8 @@ -# A CLI (snipr) Tool for Managing Neovim and VSCode Snippets +# A CLI (snip-cli) Tool for Managing Neovim and VSCode Snippets -[![Rust Build and Test](https://github.com/codeitlikemiley/snipr/actions/workflows/test.yml/badge.svg)](https://github.com/codeitlikemiley/snipr/actions/workflows/test.yml) +[![Rust Build and Test](https://github.com/codeitlikemiley/snip-cli/actions/workflows/test.yml/badge.svg)](https://github.com/codeitlikemiley/snip-cli/actions/workflows/test.yml) -[![release](https://github.com/codeitlikemiley/snipr/actions/workflows/release.yml/badge.svg)](https://github.com/codeitlikemiley/snipr/actions/workflows/release.yml) +[![release](https://github.com/codeitlikemiley/snip-cli/actions/workflows/release.yml/badge.svg)](https://github.com/codeitlikemiley/snip-cli/actions/workflows/release.yml) Note: This is an additional tools to be used with my [Neovide Neovim](https://github.com/codeitlikemiley/nvim) rust setup. @@ -10,52 +10,20 @@ Note: This is an additional tools to be used with my [Neovide Neovim](https://gi ## Installation -1. You can Download and Install [snipr](https://github.com/codeitlikemiley/snipr/releases) on Releases Page +1. You can Download and Install [snip-cli](https://github.com/codeitlikemiley/snip-cli/releases) on Releases Page Note: on MacOS you might need to go to System Preferences > Security & Privacy > General and click Open Anyway to install it Note: on Windows you might need to Add the command to ENV PATH -or Install it using Cargo +2. Install it using Cargo ```sh -cargo install snipr -``` - - - -2. Build it from source -### Clone -```sh -git clone htps://github.com/codeitlikemiley/snipr.git -cd snipr -``` - -### For MacOS -```sh -./provision.sh -``` - -### For Linux -```sh -cargo build --release -mv ./target/release/snipr /usr/local/bin/snipr -chmod +x /usr/local/bin/snipr -``` - -### For Windows -```sh -cargo build --release - -# Replace 'YourUsername' with your actual username -Move-Item .\target\release\snipr.exe C:\Users\YourUsername\bin\snipr.exe - -# Again, replace 'YourUsername' with your actual username -$env:Path += ";C:\Users\YourUsername\bin" +cargo install snip-cli --bin snip ``` ## Managing Multiple Snippets File for Different Languages -You can use the command `snipr config ` to change the Snippets File on Runtime. +You can use the command `snip config ` to change the Snippets File on Runtime. Note: This is quite useful when you want to manage different Snippets File for different languages. @@ -69,20 +37,20 @@ but you can change it by setting the `SNIP_CONFIG_PATH` environment variable. 1. Help ```sh -snipr +snip # or -snipr --help +snip --help ```
Output ```sh -snipr +snip /Users/uriah/.config/nvim/snippets/rust/rust.json A CLI tool for managing Neovim LuaSnip Rust snippets -Usage: snipr +Usage: snip Commands: add Adds entry to Snippet Collection file @@ -104,38 +72,38 @@ Options: 2. Add new snippet ```sh # help -snipr add --help +snip add --help # Add Snippet -snipr add --key --value --description -- "" +snip add --key --value --description -- "" ``` 3. Remove snippet ```sh # help -snipr remove --help +snip remove --help # Remove Snippet -snipr remove --key +snip remove --key ``` 4. List all snippets ```sh # help -snipr ls --help +snip ls --help # Usage -snipr ls +snip ls # List all Keys -snipr ls key +snip ls key # List all Prefixes -snipr ls prefix +snip ls prefix ```
Output ```sh -snipr ls key +snip ls key /Users/uriah/.config/nvim/snippets/rust/rust.json [src/main.rs:468] list_option = Key impl_iterator @@ -156,16 +124,16 @@ impl_clone_single_field ```sh # help -snipr update-key --help +snip update-key --help # Update Key -snipr update-key --old-key --new-key +snip update-key --old-key --new-key ```
Output ```sh -snipr update-key --old-key "Fuzz match String" --new-key "fuzzy-match-string" +snip update-key --old-key "Fuzz match String" --new-key "fuzzy-match-string" /Users/uriah/.config/nvim/snippets/rust/rust.json [src/main.rs:499] &old_key = "Fuzz match String" [src/main.rs:499] &new_key = "fuzzy-match-string" @@ -177,25 +145,25 @@ snipr update-key --old-key "Fuzz match String" --new-key "fuzzy-match-string" ```sh # help -snipr edit --help +snip edit --help # Update snippet Value -snipr edit --key --prefix --description -- "" +snip edit --key --prefix --description -- "" ``` 7. Search Snippet ```sh # help -snipr search --help +snip search --help # Search Snippet -snipr search -- "" +snip search -- "" ```
Output ```sh -snipr search key -- impl +snip search key -- impl /Users/uriah/.config/nvim/snippets/rust/rust.json [src/main.rs:490] id = Some( Key, @@ -216,16 +184,16 @@ impl_partialeq_single_field ```sh # help -snipr show --help +snip show --help # Show Snippet -snipr show +snip show ```
Output ```sh -snipr show impl_deref +snip show impl_deref /Users/uriah/.config/nvim/snippets/rust/rust.json [src/main.rs:484] &key = "impl_deref" +-------------+-------------------------------------------------------------+ @@ -258,7 +226,7 @@ Note: This can be used to switch Configuration e.g. you wanna manage Python Snip ```sh # help -snipr config --help +snip config --help # Config Snippet -snipr config +snip config ``` diff --git a/provision.sh b/provision.sh index dfe0a6c..b411885 100755 --- a/provision.sh +++ b/provision.sh @@ -1,7 +1,7 @@ #!/bin/sh cargo clean -rm snipr.pkg +rm snip.pkg cargo zigbuild --release cargo bundle --release -pkgbuild --root ./target/release/bundle/osx/snipr.app --install-location "/Applications/snipr.app" --identifier com.codeitlikemiley.snipr --version 0.1.0 --scripts ./scripts snipr.pkg \ No newline at end of file +pkgbuild --root ./target/release/bundle/osx/snip.app --install-location "/Applications/snip.app" --identifier com.codeitlikemiley.snip --version 0.1.0 --scripts ./scripts snip.pkg \ No newline at end of file diff --git a/scripts/postinstall b/scripts/postinstall index 161dfe0..db7f172 100755 --- a/scripts/postinstall +++ b/scripts/postinstall @@ -17,4 +17,4 @@ if [ -L "$USER_HOME/.local/bin/snip" ]; then fi # Create the symlink in ~/.local/bin -ln -s "/Applications/snipr.app/Contents/MacOS/snipr" "$USER_HOME/.local/bin/snip" +ln -s "/Applications/snip.app/Contents/MacOS/snip-cli" "$USER_HOME/.local/bin/snip" diff --git a/src/main.rs b/src/main.rs index af02058..429f7f8 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,19 +1,19 @@ use anyhow::{self, Context, Result}; use clap::Parser; -use snipr::actions::create_directory_and_file::create_directory_and_file; -use snipr::actions::edit_snippet_in_file::edit_snippet_in_file; -use snipr::actions::list_snippets::list_snippets; -use snipr::actions::remove_snippet_from_file::remove_snippet_from_file; -use snipr::actions::search_snippets::search_snippets; -use snipr::actions::show_snippet::show_snippet; -use snipr::actions::update_key_in_file::update_key_in_file; -use snipr::actions::write_snippet_to_file::write_snippet_to_file; -use snipr::constants::DEFAULT_SNIPPET_PATH; -use snipr::helpers::expand_home_dir::expand_home_dir; -use snipr::helpers::get_app_config::get_app_config; -use snipr::models::cli_model::Cli; -use snipr::models::commands_model::Commands; -use snipr::models::snip_config_model::SnipConfig; +use snip_cli::actions::create_directory_and_file::create_directory_and_file; +use snip_cli::actions::edit_snippet_in_file::edit_snippet_in_file; +use snip_cli::actions::list_snippets::list_snippets; +use snip_cli::actions::remove_snippet_from_file::remove_snippet_from_file; +use snip_cli::actions::search_snippets::search_snippets; +use snip_cli::actions::show_snippet::show_snippet; +use snip_cli::actions::update_key_in_file::update_key_in_file; +use snip_cli::actions::write_snippet_to_file::write_snippet_to_file; +use snip_cli::constants::DEFAULT_SNIPPET_PATH; +use snip_cli::helpers::expand_home_dir::expand_home_dir; +use snip_cli::helpers::get_app_config::get_app_config; +use snip_cli::models::cli_model::Cli; +use snip_cli::models::commands_model::Commands; +use snip_cli::models::snip_config_model::SnipConfig; use std::io::Write; #[tokio::main]