Blog: 2023-07-19

From razwiki
Revision as of 00:18, 19 July 2023 by Razzi (talk | contribs) (Created page with "It's getting late ~~ and I'm stuck trying to scratch a particular itch, yet one I have felt many times... clone-cd git clone <somerepo> The problem is I copy urls from the...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

It's getting late ~~ and I'm stuck trying to scratch a particular itch, yet one I have felt many times...

clone-cd git clone <somerepo>

The problem is I copy urls from the browser that try to helpfully have a git clone as part of them, but I don't use that, I use my function clone-cd, which sets the depth to 1 and cds into it.

Now I just came up with another solution, namely: make a git wrapper that does the above. But even before that, I have written

git clone git clone <somerepo>

many times.

First attempt was using abbr with the --position anywhere flag. But it doesn't look like having a space in the pattern works

Then I thought "maybe I can do an abbr for git and one for clone". that should work but it's pretty hacky.

Then I thought "maybe I can tap into the paste function" - this is probably actually the most straightforward solution. But I guess alt+v is not what is bound that might go straight through the terminal app as a string of keystrokes. But maybe rebinding it would work...

Ok so it didn't work at first, since I had config in my alacritty toml. But upon turning that off, I'm able to call razzi_paste:

bind \ev razzi_paste
function razzi_paste
    echo asdf
end

Ok I have something working, looks like:

function paste_avoiding_double_git_clone
    set command (commandline | string trim)
    set clipboard (wl-paste -n | string collect -N)
    if string match -q clone-cd $command
        set clipboard (echo $clipboard | string replace 'git clone ' '')
    end
    commandline -i -- $clipboard
end

and

bind \ev paste_avoiding_double_git_clone

great, flow preserved