mirror of
https://github.com/charmbracelet/gum
synced 2024-06-15 20:15:08 +02:00
docs: rework examples section
This commit is contained in:
parent
9ab722ca4f
commit
2a35019323
65
README.md
65
README.md
|
@ -336,108 +336,67 @@ See [`charmbracelet/log`](https://github.com/charmbracelet/log) for more usage.
|
||||||
|
|
||||||
## Examples
|
## Examples
|
||||||
|
|
||||||
See the [examples](./examples/) directory for more real world use cases.
|
|
||||||
|
|
||||||
How to use `gum` in your daily workflows:
|
How to use `gum` in your daily workflows:
|
||||||
|
|
||||||
#### Write a commit message
|
See the [examples](./examples/) directory for more real world use cases.
|
||||||
|
|
||||||
Prompt for input to write git commit messages with a short summary and
|
* Write a commit message:
|
||||||
longer details with `gum input` and `gum write`.
|
|
||||||
|
|
||||||
Bonus points: use `gum filter` with the [Conventional Commits
|
|
||||||
Specification](https://www.conventionalcommits.org/en/v1.0.0/#summary) as a
|
|
||||||
prefix for your commit message.
|
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
git commit -m "$(gum input --width 50 --placeholder "Summary of changes")" \
|
git commit -m "$(gum input --width 50 --placeholder "Summary of changes")" \
|
||||||
-m "$(gum write --width 80 --placeholder "Details of changes (CTRL+D to finish)")"
|
-m "$(gum write --width 80 --placeholder "Details of changes")"
|
||||||
```
|
```
|
||||||
|
|
||||||
#### Open files in your `$EDITOR`
|
* Open files in your `$EDITOR`
|
||||||
|
|
||||||
By default, `gum filter` will display a list of all files (searched
|
|
||||||
recursively) through your current directory, with some sensible ignore settings
|
|
||||||
(`.git`, `node_modules`). You can use this command to easily to pick a file and
|
|
||||||
open it in your `$EDITOR`.
|
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
$EDITOR $(gum filter)
|
$EDITOR $(gum filter)
|
||||||
```
|
```
|
||||||
|
|
||||||
#### Connect to a TMUX session
|
* Connect to a `tmux` session
|
||||||
|
|
||||||
Pick from a running `tmux` session and attach to it. Or, if you're already in a
|
|
||||||
`tmux` session, switch sessions.
|
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
SESSION=$(tmux list-sessions -F \#S | gum filter --placeholder "Pick session...")
|
SESSION=$(tmux list-sessions -F \#S | gum filter --placeholder "Pick session...")
|
||||||
tmux switch-client -t $SESSION || tmux attach -t $SESSION
|
tmux switch-client -t $SESSION || tmux attach -t $SESSION
|
||||||
```
|
```
|
||||||
|
|
||||||
<img src="https://stuff.charm.sh/gum/pick-tmux-session.gif" width="600" alt="Picking a tmux session with gum filter" />
|
* Pick a commit hash from `git` history
|
||||||
|
|
||||||
#### Pick commit hash from your Git history
|
|
||||||
|
|
||||||
Filter through your git history searching for commit messages, copying the
|
|
||||||
commit hash of the commit you select.
|
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
git log --oneline | gum filter | cut -d' ' -f1 # | copy
|
git log --oneline | gum filter | cut -d' ' -f1 # | copy
|
||||||
```
|
```
|
||||||
|
|
||||||
<img src="https://stuff.charm.sh/gum/pick-commit.gif" width="600" alt="Picking a commit with gum filter" />
|
* Simple [`skate`](https://github.com/charmbracelet/skate) password selector.
|
||||||
|
|
||||||
#### Skate Passwords
|
|
||||||
|
|
||||||
Build a simple (encrypted) password selector with [Skate](https://github.com/charmbracelet/skate).
|
|
||||||
|
|
||||||
Save all your passwords to [Skate](https://github.com/charmbracelet/skate) with `skate set github@pass.db PASSWORD`, etc...
|
|
||||||
|
|
||||||
```
|
```
|
||||||
skate list -k | gum filter | xargs skate get
|
skate list -k | gum filter | xargs skate get
|
||||||
```
|
```
|
||||||
|
|
||||||
<img src="https://stuff.charm.sh/gum/skate-pass.gif" width="600" alt="Selecting a skate value with gum" />
|
* Uninstall packages
|
||||||
|
|
||||||
#### Choose packages to uninstall
|
|
||||||
|
|
||||||
List all packages installed by your package manager (we'll use `brew`) and
|
|
||||||
choose which packages to uninstall.
|
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
brew list | gum choose --no-limit | xargs brew uninstall
|
brew list | gum choose --no-limit | xargs brew uninstall
|
||||||
```
|
```
|
||||||
|
|
||||||
#### Choose branches to delete
|
* Clean up `git` branches
|
||||||
|
|
||||||
List all branches and choose which branches to delete.
|
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
git branch | cut -c 3- | gum choose --no-limit | xargs git branch -D
|
git branch | cut -c 3- | gum choose --no-limit | xargs git branch -D
|
||||||
```
|
```
|
||||||
|
|
||||||
#### Choose pull request to checkout
|
* Checkout GitHub pull requests with [`gh`](https://cli.github.com/)
|
||||||
|
|
||||||
List all PRs for the current GitHub repository and checkout the chosen PR (using [`gh`](https://cli.github.com/)).
|
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
gh pr list | cut -f1,2 | gum choose | cut -f1 | xargs gh pr checkout
|
gh pr list | cut -f1,2 | gum choose | cut -f1 | xargs gh pr checkout
|
||||||
```
|
```
|
||||||
|
|
||||||
#### Pick command from shell history
|
* Copy command from shell history
|
||||||
|
|
||||||
Pick a previously executed command from your shell history to execute, copy,
|
|
||||||
edit, etc...
|
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
gum filter < $HISTFILE --height 20
|
gum filter < $HISTFILE --height 20
|
||||||
```
|
```
|
||||||
|
|
||||||
#### Sudo password input
|
* `sudo` replacement
|
||||||
|
|
||||||
See visual feedback when entering password with masked characters with `gum
|
|
||||||
input --password`.
|
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
alias please="gum input --password | sudo -nS"
|
alias please="gum input --password | sudo -nS"
|
||||||
|
|
Loading…
Reference in a new issue