Skip to content

Examples

Michał Nowotnik edited this page Jun 20, 2022 · 9 revisions

Here you will find usage examples.

Feel free to make a PR and add your own! Don't forget to attribute it to yourself.

Table of Contents

git

Copy a ticket id from a feature branch to the message

  - pattern: 'git commit  -m "'
    selectOne: true
    cmd: git rev-parse --abbrev-ref HEAD
    map: '{{ .item | split "/" | mapGet "_1" }}'

Before:

~/Projects/fzshell feature/FZ-123
❯ git commit -m "

After:

~/Projects/fzshell feature/FZ-123
❯ git commit -m "FZ-123

Alias for push origin

Expands pusho into push origin command that uses current branch as a origin.

  - pattern: 'git pusho'
    selectOne: true
    cmd: "git rev-parse --abbrev-ref HEAD"
    map: ' push -u origin {{.item}}'
    replacement: "git {{.item}}"

Before:

~/Projects/fzshell feature/FZ-123
❯ git pusho

After:

~/Projects/fzshell feature/FZ-123
❯ git push -u origin feature/FZ-123

Choose a commit to rebase on

  - pattern: '(git rebase *-?i?) *'
    replacement: '{{._1}} {{.item | splitList " " | listGet 0}}'
    cmd: git log --oneline
    preview: >
      git show --color '{{.item | splitList " " | listGet 0 }}'

docker

Remove a docker container

  - pattern: "docker rm"
    cmd: "docker ps -a --format '{{.Names}}\t{{.ID}}\t{{.Image}}\t{{.Status}}'"
    map: ' {{ .item | split "\t" | mapGet "_0" }}'

Remove a docker image

  - pattern: "docker rmi"
    cmd: "docker images --format '{{.Repository}}:{{.Tag}}\t{{.ID}}'"
    map: ' {{ .item | splitList "\t" | last }}'
    preview: '{{ shell "docker image inspect " .item }}'

kubectl

Execute a command on a pod

  - pattern: 'kubectl (.+) (pod/)'
    cmd: "kubectl get pods"
    map: '{{ .item | split " " | mapGet "_0" }}'
    headerLines: 1

jq

Explore json by gradually narrowing your result

  - pattern: "jq '?(\\.[^']*)'? (\\w+.json)"
    replacement: jq '{{._1}}[{{ .item }}]' {{._2}}
    cmd: 'jq $1 $2 | jq keys | jq  ". []"'
    preview: jq -C '{{._1}}[{{.item}}]'  {{._2}}

Matching pattern example: jq . pets.json

Alternative pattern:

  - pattern: 'cat (\w+\.json) \| jq (\..*)'
    cmd: 'jq $2 $1 | jq keys | jq  ". []"'
    map: '{{ ternary (printf ".%s" .item) (printf "[%s]" .item) (hasPrefix "\"" .item) }}'
    preview: jq -C '{{._2}}[{{.item}}]'  {{._1}}

Matching pattern example: cat pets.json | jq .

maven

Extract class name and run a test

  - pattern: "mvn .+ -Dtest="
    cmd: find . -name '*.java'
    map: '{{$v := .item | splitList "/" | last }}{{ regexReplaceAll "\\.\\w+$" $v "" }}'