bayleeadamoss / zazu-snippets

The Unlicense
9 stars 3 forks source link

Bypass the "snip" syntax to search snippets #8

Closed nashrocks13 closed 6 years ago

nashrocks13 commented 6 years ago

I really like the idea of being able to search through saved snippets from a launcher like this, but having to type "snip" and then the search term every time seems like a waste.

Would it be possible to configure this plugin so that saved snippets appear in Zazu alongside other items based on any search (i.e., "worksig" instead of "snip worksig"), or is the "snip" syntax required by Zazu (or problematic for other reasons)?

afaur commented 6 years ago

Yes, one possible way to accomplish this...

bayleedev commented 6 years ago

In your fork you can have a hotkey go to the prefix search, which opens a normal looking zazu window but only allows one plugin to respond... similar to the clipboard history.

bayleedev commented 6 years ago

You could make a pr for that too if you want. Shortcuts are overwriteable by the user so it's not a huge commitment from this plugin.

nashrocks13 commented 6 years ago

Okay, thanks for the suggestions.

NOTE: I'm not very familiar with JavaScript, so I'm fumbling my way along here.

I forked it and tried to make those modifications, but I've done something wrong. Initially it just wasn't working, but now it gives and error and says that rootScript is not a recognized input block. I already switched back to PrefixScript, so I'm not sure why it's giving me that error.

I also tried to add a Hotkey in addition to the primary Read, but that hasn't been triggering either.

Can you take a look and help me identify where I've messed it up? https://github.com/nashrocks13/zazu-snippets

afaur commented 6 years ago

@nashrocks13

... says that rootScript is not a recognized input block. I already switched back to PrefixScript, so I'm not sure why it's giving me that error.

Hotkey blocks are of type external. This means that a new section for external blocks must be created and your block should be added there. This may have been causing other errors to show up.

I also tried to add a Hotkey in addition to the primary Read, but that hasn't been triggering either.

You probably did that correctly, but zazu didn't like it because the block type wasn't allowed in the input or output sections.

Here is an example...

{
  "name": "Zazu Snippets",
  "icon": "snip.svg",
  "stylesheet": "css/preview.css",
  "blocks": {
    "input": [
      {
        "id": "Read",
        "type": "PrefixScript",
        "prefix": "'",
        "space": false,
        "args": "Required",
        "script": "src/read.js",
        "connections": [
          "Copy"
        ]
      },
      {
        "id": "Write",
        "type": "PrefixScript",
        "prefix": "snipc",
        "space": true,
        "args": "Required",
        "script": "src/write.js",
        "connections": [
          "WriteSnippet"
        ]
      },
      {
        "id": "Delete",
        "type": "PrefixScript",
        "prefix": "snipd",
        "space": true,
        "args": "Required",
        "script": "src/delete.js",
        "connections": [
          "DeleteSnippet"
        ]
      }
    ],
    "output": [
      {
        "id": "Copy",
        "type": "CopyToClipboard",
        "text": "{value}"
      },
      {
        "id": "WriteSnippet",
        "type": "UserScript",
        "script": "src/writeSnippet.js",
        "value": "{value}"
      },
      {
        "id": "DeleteSnippet",
        "type": "UserScript",
        "script": "src/deleteSnippet.js",
        "value": "{value}"
      }
    ],
    "external": [
      {
        "id": "Direct",
        "type": "Hotkey",
        "hotkey": "CmdOrCtrl+Alt+Space",
        "connections": [ "Write" ]
      }
    ]
  }
}

I moved your Hotkey block into an external section and made it call the Write input block. This should trigger zazu to open but make it so what you type in will be the snippet name.

nashrocks13 commented 6 years ago

Thanks, @afaur!

I implemented that change, but I'm still getting the same "rootScript" error when I reload config. I tried disconnecting from my fork by editing the .json file to point to the original, and then back again – same issue.

Is there anything else I can do to clear that up, short of starting over?

nashrocks13 commented 6 years ago

@afaur @blainesch I'm still getting that "rootScript" error every time I reload Zazu:

02-02-2018-03-22-12

I tried deleting the current zazu.json and creating a new, identical one (because I can't see anything in the code that explains the error), but that didn't work. Any suggestions?

afaur commented 6 years ago

I added the hotkey to the plugin and merged the changes so you should be able to switch back to using tinytacoteam/zazu-snippets in your .zazurc.json file.

If you need to add additional hotkeys I would...

If you add some hotkeys for the other commands and want to submit a pull request I will add it to the codebase. I will then add this and any other default hotkeys to the documentation.

afaur commented 6 years ago

I am unsure why you were still getting that error so I took this approach. I tested it locally and it should work, but if you have issues still please let me know.

nashrocks13 commented 6 years ago

I opened up the json file for nashrocks13 from the plugins folder, and the code there did not reflect my updates in GitHub. That seems to be why I was getting the error continually, though I'm not sure why they are disconnected (or how to reconnect them).

I've tried deleting and reinstalling Zazu entirely, but some pieces of the app seem to remain, and the connection to my fork is still messed up (also deleted and reforked, which also doesn't work because of the disconnection).

Are there any special steps I need to take to completely wipe Zazu from my machine and start over? That seems to be the only way I'm going to fix the issue.

afaur commented 6 years ago

I opened up the json file for nashrocks13 from the plugins folder, and the code there did not reflect my updates in GitHub. That seems to be why I was getting the error continually, though I'm not sure why they are disconnected (or how to reconnect them).

  • You should be able to delete the entire nashrocks13/zazu-snippets folder from that plugins folder.
  • If you happen to have any snippets back them up first
  • Afterwards when you run zazu you can choose reload plugins from the tray icon menu.
  • This should attempt to refetch any missing plugin projects and place them in your plugins folder
  • You should see the /zazu-snippets folder be recreated in plugins folder
  • Any time you run the reload plugins zazu reads your .zazurc.json file and...
  • Ensures that every plugin specified in that file has a folder inside that plugins folder
  • Any folder that is missing in the plugin folder will be added from latest changes in master on github

I've tried deleting and reinstalling Zazu entirely, but some pieces of the app seem to remain, and the connection to my fork is still messed up (also deleted and reforked, which also doesn't work because of the disconnection).

  • Your absolutely correct in your observations. With the zazu app most everything in two primary spots...
  • The .zazurc.json file which exists in your home directory as a hidden dot file
  • The .zazu folder which exists in your home directory as a hidden folder
  • It is probably not needed that you would have to delete everything however you might need to...
  • Remove .zazu/plugins/nashrocks13/zazu-snippets manually
  • Remove .zazu/plugins/tinytacoteam/zazu-snippets manually
  • See Afterwards when you run zazu you can choose reload plugins... section above.

Are there any special steps I need to take to completely wipe Zazu from my machine and start over? That seems to be the only way I'm going to fix the issue.

  • See Zazu itself most everything in two primary spots... section above.
nashrocks13 commented 6 years ago

Every time I try to delete the nashrocks folder from the plugins folder, I get an error saying the item is no longer located there and cannot be found. I successfully moved the folder elsewhere, but even when I try to delete the folder housing that folder, I get the error for the new parent folder.

Strange...

Not sure why that happens, but I renamed the old folder and left it stowed away in the plugins folder for now. If you have any insights or suggestions, please let me know.

I reloaded plugins though, and I think things are finally working. Thanks for your patient help!