Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Awesome! #20

Closed
darkpandarts opened this issue Aug 6, 2023 · 6 comments
Closed

Awesome! #20

darkpandarts opened this issue Aug 6, 2023 · 6 comments
Assignees
Labels
question Further information is requested

Comments

@darkpandarts
Copy link

Absolutely awesome program! :o) Hat tip!!

So i was thinking this is great for getting the vscode windows open. However, i was thinking it be made even better for when the user uses a dedicated terminal to test the program vs using the inbuilt vscode term.

When I code terraform, I can end up with 4-5 vscode instances open - all instantiated from different directories. Thus I have a split pane terminator with x4 terminals that are linked to each open vscode instance. My normal workflow is to cd to the directory from the terminal, then launch vscode using code ..

Obviously your app is much faster at opening the vscode window, but then I still need to type in a cd command to go to the matching folder. As a possible solution, would it be possible to get rofi-vscode-mode to copy the workspace path into the copy buffer, so i could then paste to cd in the terminal?

Maybe you have a better idea as to how to improve this workflow? Anyways, look forward to your reply. :)

@fuljo
Copy link
Owner

fuljo commented Aug 8, 2023

Hi there and thanks for the appreciation!

I've read your workflow and it's for sure a common case.
It's very easy to open an external terminal in your current VSCode Workspace:

  1. Open the command palette (Ctrl+Shift+P)
  2. Use the command "Open New External Terminal" (in my config it's also bound to Ctrl+Shift+C)

To control which terminal is opened, change the setting terminal.external.linuxExec.

However, this still spawns a new terminal. Let's see what you can do to cd into a recent workspace without leaving the terminal.
From the README you can see that this project also gives you a command line tool called vscode-recent that provides the same entries as the Rofi plugin.
You can use it in combination with Rofi, fzf or dmenu to select a directory and cd into it:

cd $(vscode-recent -F absolute-path | rofi -dmenu)

I'm sure you can also bind this command to a key combo in your shell if you put some time into it.
A lazier alternative, which is what I actually use, is to install fzf in your shell, use it to look through your history with Ctrl+R and bring up the command you're looking for.

Implementing a custom "copy" functionality into the Rofi plugin seems a little overkill to me, since you still need to paste the workspace path into the terminal.

I hope this is clear enough, as I've put it together after work 😆
If it's too cryptic, let me know.

@fuljo fuljo self-assigned this Aug 8, 2023
@fuljo fuljo added the question Further information is requested label Aug 8, 2023
@darkpandarts
Copy link
Author

darkpandarts commented Aug 8, 2023

This seems like a potentially viable solution! However, I'm uncertain as to how to use with rofi-bangs which is what I'm currently using as the "meta" launcher

https://github.com/gotbletu/shownotes/blob/master/rofi-bangs.md

I'm a bit new to rofi and would be very grateful if you had some advice as to how I could integrate your suggestion with terminator and rofi-bangs

This is the entry in my current rofi-bangs script:

# vscode workspace selector
COMMANDS["{vsc"]="rofi -show vscode-recent -modi vscode-recent"
LABELS["{vsc"]=""

Thanks for your patience on this! :o)

@fuljo
Copy link
Owner

fuljo commented Aug 8, 2023

My suggestion was actually to set a keybinding inside your shell (I wrote terminal before, sorry) to launch that command. So you would manually open a new terminal panel in terminator, then press some key combination like Alt-C and the Rofi menu would come up. You select the entry you want and the cd /some/directory/you/selected command is invoked. No need to pass through rofi-bangs.

However, if you prefer to stick to rofi-bangs and the copy-paste workflow you described in the first post, you can do as follows. I'm assuming you're using X11, but this would be similar in Wayland.

  1. Install xclip
  2. Add the following command to your rofi-bangs configuration
    vscode-recent | rofi -dmenu | xclip -selection clipboard -in
    Basically, all that rofi -dmenu does is getting the entries from the vscode-recent command and showing them to you. Once you select an entry, it gets passed to the xclip command, which puts the entry in your clipboard. Now you can just paste it into terminator as you originally suggested.

@darkpandarts
Copy link
Author

hmmm. This seems good but it does not work as expected with rofi-bangs

Executing the following does not open the vscode window but successfully copies the workspace url:

vscode-recent | rofi -dmenu | xclip -selection clipboard -in

The following opens the dir in vscode, but fails to copy the directory

rofi -show vscode-recent -modi vscode-recent | rofi -demnu | xclip -selection clipboard -in

Is there a way to get both at once?

@fuljo
Copy link
Owner

fuljo commented Aug 9, 2023

Then just do the dumb thing and create a script that does both:

#!/usr/bin/env bash

# get the selection
sel=$(vscode-recent | rofi -dmenu)

if [[ -n "$sel" ]]; then
        # open in vscode (after expanding the tilde)
        sh -c "code $sel"
        # copy to clipboard
        echo -n "$sel" | xclip -selection clipboard -in
fi

You save this in ~/.local/bin/my-rofi-vscode and give it execution privileges.

Then call it from rofi-bangs.

@darkpandarts
Copy link
Author

Sorry, just saw this! this works perfectly thank you!!! I just added a cd to this line and it's perfect!!

echo -n "cd $sel" | xclip -selection clipboard -in

Many thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants