Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/omakoto/compromise
Go Framework for Writing Shell Completion for Bash / Zsh (with Go/ADB completion)
https://github.com/omakoto/compromise
bash bash-completion go golang zsh zsh-completion
Last synced: 2 months ago
JSON representation
Go Framework for Writing Shell Completion for Bash / Zsh (with Go/ADB completion)
- Host: GitHub
- URL: https://github.com/omakoto/compromise
- Owner: omakoto
- License: mit
- Created: 2018-06-12T04:08:02.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2023-08-24T03:56:42.000Z (over 1 year ago)
- Last Synced: 2024-06-20T01:55:53.463Z (7 months ago)
- Topics: bash, bash-completion, go, golang, zsh, zsh-completion
- Language: Go
- Homepage:
- Size: 287 KB
- Stars: 4
- Watchers: 1
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[![Build Status](https://travis-ci.org/omakoto/compromise.svg?branch=master)](https://travis-ci.org/omakoto/compromise)
# Compromise (and Bash/Zsh completion for ADB and Go)Compromise is a Go framework for writing shell completion for Bash / Zsh.
Currently it comes with the following two sets of completions:
- ADB (Android Debug Bridge, including several shell commands), fastboot, atest, m/mm/mmm, etc
- Examples:
- Most `adb` subcommands, major subcommands for `adb shell [am|pm|settings]`
(e.g. `am start-activity [flags] INTENT`), and service name for `adb shell [dumpsys|cmd]`
- Flags for `fastboot`
- Build modules and some pseudo build targets for `m` (`m MODULE`, `m installclean`, etc)
- `atest MODULE`, `atest FILENAME#method1,method2,...`
(* _Method name completion doesn't seem work well on Zsh_)
- Other commands such as `runahat PROCESSNAME|PID` and `stacks PROCESSNAME|PID`
- Go## Features
- Define completion in [an obvious-ish language](src/cmds/compromise-go/go.go) that supports both Bash and Zsh.
- Generate dynamic candidates with [custom Go functions](src/cmds/compromise-adb/adb.go).
- Show candidate description not only on Zsh but on Bash too.
- On Bash, completion candidates look like this (type `adb[SPACE][TAB]`):
- Interactive selection (searching candidates with a query) on Bash using [fzf](https://github.com/junegunn/fzf).
See the next section for how to enable it.### Enabling Interactive Item Selection with [fzf](https://github.com/junegunn/fzf) on Bash (and maybe on Zsh too)
If [fzf](https://github.com/junegunn/fzf) is installed, Compromise can invoke it
to let you interactively search for a candidate (which is the default behavior on Bash).Try pressing `[TAB]` twice to invoke fzf. (e.g. try `adb[SPACE][TAB][TAB]`)
- If you want to disable it, add `export COMPROMISE_USE_FZF=0` to your `~/.bashrc`.
- You can enable it on Zsh too by adding `export COMPROMISE_USE_FZF=1` to your `~/.zshrc`,
but Zsh won't redraw the current line after fzf finishes, so it's a bit awkward.
(For now, just refresh the command line by pressing `[ALT]+[Shift]+R`)
## Installing ADB and/or Go CompletionAssuming you have the `go` command installed, just run the following commands in your shell.
```bash
# Get and install the binaries.
go get -v -u github.com/omakoto/compromise/src/cmds/...# Also install fzf, if you haven't already.
go get -v -u github.com/junegunn/fzf# Then to install completion, run them on your shell.
# Add them to your shell's RC file (.bashrc or .zshrc) to make them persistent.
. <(compromise-adb) # Install ADB / fastboot / atest / m* completion
. <(compromise-go) # Install Go completion# If you get "command not found", add ~/go/bin/ to your PATH, which is the default install
# location.```
*NOTE `go run` won't work; you need to actually compile them.*
### Creating Aliases to ADB Subcommands
- `compromise-adb` also installs completion for some "shorthand" commands,
so if you have following aliases, completion will work for them too.```bash
alias logcat="adb logcat"
alias dumpsys="adb shell dumpsys"
alias cmd="adb shell cmd"
alias am="adb shell am"
alias pm="adb shell pm"
alias settings="adb shell settings"
alias akill="adb shell kill"
alias akillall="adb shell killall"
:
```
For the full supported command name list, see [the source code](src/cmds/compromise-adb/adb.go).
- If you do not want to install completion for all the listed commands
in the source file, pass the command name you want to use as arguments. Example:```bash
. <(compromise-adb adb dumpsys) # Only install competion for the adb and dumpsys commands.# or, disable selectively.
. <(compromise-adb - atest) # Install everything except for the atest completion.
```## Customization
Some parameters are tunable via environmental variables.
See [this file](src/compromise/compenv/compenv.go).## Caveat
It's still in an alpha stage. Details are subject to change, but feedback is welcome.
## Known Issues
- Not heavily tested on Zsh yet.
## TODOs
- Write tests for compromise-adb/go.