Skip to content

Commit

Permalink
Merge pull request #5 from taylorzr/some_tweaks
Browse files Browse the repository at this point in the history
fzf headers, use EDITOR, and some fixes
  • Loading branch information
taylorzr authored Nov 12, 2023
2 parents 6835236 + 8eff0d5 commit 94daf46
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 61 deletions.
85 changes: 38 additions & 47 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,24 @@
# Kitty-Meow

Meow is a kitty terminal extension for working with projects. It allows you to easily switch between
projects, and load them either from local directories or github.
Meow is a kitty terminal extension for working with projects, where each kitty tab is a different
project. It allows you to fuzzy switch between projects, and load them either from local directories or github.

If you've used tmux sessions. This is similar to switching between sessions, but allows you to
If you've used tmux, this is similar to switching between sessions, but allows you to
create new sessions as well.

![Meow Screenshot](screenshot.png)

## Usage

Call your project mapping, e.g. ctrl-p, and hit enter to select. Initially, tabs & local projects
are listed, but you can show remote, local project only, or tabs only.

On select

- if the project is already in a tab, meow switches to that tab
- if the project is a local dir, meow creates a new tab
- if the project is github, meow clones to the first --dir, and creates a new tab

## Installation

```sh
Expand All @@ -20,8 +31,8 @@ Depends on [fzf](https://github.com/junegunn/fzf/) and [jq](https://github.com/s

You'll need to:

* create mappings
* set your github token as env
- create mappings
- set your github token as env

For example:

Expand All @@ -30,14 +41,14 @@ For example:
env GITHUB_TOKEN=<github_token>
env BIN_PATH=/opt/homebrew/bin/ # probably only needed on macs
map ctrl+space kitten meow/load_project.py --dir $HOME/code/ --user my_cool_self --org my_cool_org
map ctrl+p kitten meow/load_project.py --dir $HOME/code/ --user my_cool_self --org my_cool_org
map ctrl+shift+n kitten meow/new_project.py --dir $HOME/code/
map ctrl+shift+x kitten meow/kill_old_projects.py
map ctrl+shift+g kitten meow/cache_all_repos.py --org my_cool_org
map ctrl+- goto_tab -1
```

### kitty mappings
## Kitty Mappings

#### Loading projects

Expand All @@ -46,20 +57,20 @@ Create a mapping for loading projects. The pattern is:
```conf
# ~/.config/kitty/kitty.conf
map ctrl+space kitten meow/load_project.py --dir $HOME/code/ --user <you> --org <github_org>
map ctrl+p kitten meow/load_project.py --dir $HOME/code/ --user <you> --org <github_org>
```

--dir can be provided multiple times.

* when a dir ends in /, meow shows all it's subdirs
* otherwise, meow only shows that specific dir
- when a dir ends in /, meow shows all it's subdirs
- otherwise, meow only shows that specific dir

For example, I use:

```conf
# ~/.config/kitty/kitty.conf
map ctrl+space kitten meow/load_project.py --dir $HOME/code/ --dir $HOME --dir $HOME/.config/kitty/meow --org my_cool_org
map ctrl+p kitten meow/load_project.py --dir $HOME/code/ --dir $HOME --dir $HOME/.config/kitty/meow --org my_cool_org
```

On mac, paths are goofy. You proabably need to set env BIN_PATH as well. This should be the dir
Expand All @@ -73,14 +84,21 @@ env BIN_PATH=/opt/homebrew/bin/

#### Caching github repositories

Something about big github orgs, talk about how you don't have to use caching. If file doesn't exist
it'll fetch from github everytime.
If you work in an org with lots of repos, loading remote projects can be slow. You can create a
binding that will cache all the repos for orgs. This is a manual process, just run it whenever you
need to update the list of projects for an org.

```conf
map ctrl+shift+g kitten meow/cache_all_repos.py --org my_cool_org
```

### github auth
Just like the load_project mapping, you can specify multiple users and orgs in your cache mapping.
You might want these to be different than users and orgs in your load_project mapping, because an
org might have lots of repos, but your user just a few. Any uncached users/orgs repos will be
loaded from github on every call to load_projects. And the cache never expires, you must call
cache_all_repos to refresh it.

## Github Auth

You need to create a github token, and set it as env GITHUB_TOKEN. Because I commit kitty.conf to my
dotfiles, I put any secrets in an extra conf file:
Expand All @@ -99,38 +117,11 @@ env GITHUB_TOKEN=<github_token>

You need to put env in your kitty config, not .zshrc. More about that [here](https://sw.kovidgoyal.net/kitty/faq/#things-behave-differently-when-running-kitty-from-system-launcher-vs-from-another-terminal)

## Usage

Call your mapping, e.g. ctrl-space

* initially, tabs & local projects are listed
* ctrl-t lists all tabs
* ctrl-p lists all local projects
* ctrl-g lists all github repos
* ctrl-r returns to lists tabs & projects
* enter selects an item

On select

* if the project is already in a tab, meow switches to that tab
* if the project is a local dir, meow creates a new tab
* if the project is github, meow clones to the first --dir, and creates a new tab


## Caching

Just like the load_project mapping, you can specify multiple users and orgs in your cache mapping. You might want these to be different than
users and orgs in your load_project mapping, because an org might have lots of repos, but your user
just a few.

Any uncached users/orgs repos will be loaded from github on every call to load_projects. And the cache never expires, you must call cache_all_repos to refresh it.

## TODO

* record short video demo
* configurable fzf bindings
* selectable dir to clone to?
* some people might use 1 dir for work and one for personal?
* maybe use flags like --login=user=taylorzr --login=org=my_cool_org
* combine the scripts into one cli with subcommands
* configurable layout, shouldn't assume vim and 2 panes
- record short video demo
- configurable fzf bindings
- selectable dir to clone to?
- some people might use 1 dir for work and one for personal?
- maybe use flags like --login=user=taylorzr --login=org=my_cool_org
- combine the scripts into one cli with subcommands
31 changes: 17 additions & 14 deletions load_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,25 +67,26 @@ def main(args: List[str]) -> str:

bin_path = os.getenv("BIN_PATH", "")

default_prompt = "🐈 tabs&projects"
default_prompt = "🐈project"
flags = []
for org in opts.orgs:
flags.append(f"--org {org}")
for user in opts.users:
flags.append(f"--user {user}")
# NOTE: Can't use ' char within any of the binds
binds = [
'ctrl-r:change-prompt({0}> )+reload(printf "{1}")'.format(
default_prompt, "\n".join(tabs_and_projects)
),
'ctrl-t:change-prompt(🐈 tabs> )+reload(printf "{0}")'.format("\n".join(tabs)),
'ctrl-p:change-prompt(🐈 projects> )+reload(printf "{0}")'.format(
f"ctrl-r:change-prompt(🐈remote> )+reload({bin_path}python3 ~/.config/kitty/meow/get_all_repos.py {' '.join(flags)})",
'ctrl-t:change-prompt(🐈tabs> )+reload(printf "{0}")'.format("\n".join(tabs)),
'alt-p:change-prompt(🐈projects> )+reload(printf "{0}")'.format(
"\n".join(projects)
),
f"ctrl-g:change-prompt(🐈 github> )+reload({bin_path}python3 ~/.config/kitty/meow/get_all_repos.py {' '.join(flags)})",
'alt-l:change-prompt({0}> )+reload(printf "{1}")'.format(
default_prompt, "\n".join(tabs_and_projects)
),
]
args = [
f"{bin_path}fzf",
f"--header=ctrl-r: remote | alt-p: project | ctrl-t: tabs | alt-l: tabs&projects",
f"--prompt={default_prompt}> ",
f"--bind={','.join(binds)}",
]
Expand Down Expand Up @@ -134,7 +135,7 @@ def handle_result(
boss.call_remote_control(None, ("focus-tab", "--match", f"title:^{dir}$"))
return

window = boss.call_remote_control(
window_id = boss.call_remote_control(
None,
(
"launch",
Expand All @@ -143,13 +144,15 @@ def handle_result(
"--tab-title",
dir,
"--cwd",
f"{path}",
"zsh",
"--interactive",
"-c",
"nvim",
path,
),
)

parent_window = boss.window_id_map.get(window_id)

# start editor and another window
boss.call_remote_control(parent_window, ("send-text", "${EDITOR:-vim}\n"))
boss.call_remote_control(
window, ("launch", "--type", "window", "--dont-take-focus", "--cwd", "current")
parent_window,
("launch", "--type", "window", "--dont-take-focus", "--cwd", "current"),
)

0 comments on commit 94daf46

Please sign in to comment.