Skip to content

Commit

Permalink
Add config option to overwrite used shell (knqyf263#200)
Browse files Browse the repository at this point in the history
Signed-off-by: Tobias Brumhard <[email protected]>
  • Loading branch information
brumhard authored May 8, 2023
1 parent 154052b commit 803bc98
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 28 deletions.
39 changes: 20 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,33 +36,33 @@ So I made it possible to register snippets with description and search them easi

- [Main features](#main-features)
- [Examples](#examples)
- [Register the previous command easily](#register-the-previous-command-easily)
- [Register the previous command easily](#register-the-previous-command-easily)
- [bash](#bash-prev-function)
- [zsh](#zsh-prev-function)
- [fish](#fish)
- [Select snippets at the current line (like C-r)](#select-snippets-at-the-current-line-like-c-r)
- [bash](#bash)
- [zsh](#zsh)
- [fish](#fish-1)
- [Copy snippets to clipboard](#copy-snippets-to-clipboard)
- [fish](#fish)
- [Select snippets at the current line (like C-r)](#select-snippets-at-the-current-line-like-c-r)
- [bash](#bash)
- [zsh](#zsh)
- [fish](#fish-1)
- [Copy snippets to clipboard](#copy-snippets-to-clipboard)
- [Features](#features)
- [Edit snippets](#edit-snippets)
- [Sync snippets](#sync-snippets)
- [Edit snippets](#edit-snippets)
- [Sync snippets](#sync-snippets)
- [Hands-on Tutorial](#hands-on-tutorial)
- [Usage](#usage)
- [Snippet](#snippet)
- [Configuration](#configuration)
- [Selector option](#selector-option)
- [Tag](#tag)
- [Sync](#sync)
- [Auto Sync](#auto-sync)
- [Selector option](#selector-option)
- [Tag](#tag)
- [Sync](#sync)
- [Auto Sync](#auto-sync)
- [Installation](#installation)
- [Binary](#binary)
- [Mac OS X / Homebrew](#mac-os-x--homebrew)
- [RedHat, CentOS](#redhat-centos)
- [Debian, Ubuntu](#debian-ubuntu)
- [Archlinux](#archlinux)
- [Build](#build)
- [Binary](#binary)
- [Mac OS X / Homebrew](#mac-os-x--homebrew)
- [RedHat, CentOS](#redhat-centos)
- [Debian, Ubuntu](#debian-ubuntu)
- [Archlinux](#archlinux)
- [Build](#build)
- [Migration](#migration)
- [Contribute](#contribute)

Expand Down Expand Up @@ -227,6 +227,7 @@ Run `pet configure`
selectcmd = "fzf" # selector command for edit command (fzf or peco)
backend = "gist" # specify backend service to sync snippets (gist or gitlab, default: gist)
sortby = "description" # specify how snippets get sorted (recency (default), -recency, description, -description, command, -command, output, -output)
cmd = ["sh", "-c"] # specify the command to execute the snippet with
[Gist]
file_name = "pet-snippet.toml" # specify gist file name
Expand Down
10 changes: 7 additions & 3 deletions cmd/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,14 @@ func editFile(command, file string) error {

func run(command string, r io.Reader, w io.Writer) error {
var cmd *exec.Cmd
if runtime.GOOS == "windows" {
cmd = exec.Command("cmd", "/c", command)
if len(config.Conf.General.Cmd) > 0 {
cmd = exec.Command(config.Conf.General.Cmd[0], append(config.Conf.General.Cmd[1:], command)...)
} else {
cmd = exec.Command("sh", "-c", command)
if runtime.GOOS == "windows" {
cmd = exec.Command("cmd", "/c", command)
} else {
cmd = exec.Command("sh", "-c", command)
}
}
cmd.Stderr = os.Stderr
cmd.Stdout = w
Expand Down
13 changes: 7 additions & 6 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,13 @@ type Config struct {

// GeneralConfig is a struct of general config
type GeneralConfig struct {
SnippetFile string `toml:"snippetfile"`
Editor string `toml:"editor"`
Column int `toml:"column"`
SelectCmd string `toml:"selectcmd"`
Backend string `toml:"backend"`
SortBy string `toml:"sortby"`
SnippetFile string `toml:"snippetfile"`
Editor string `toml:"editor"`
Column int `toml:"column"`
SelectCmd string `toml:"selectcmd"`
Backend string `toml:"backend"`
SortBy string `toml:"sortby"`
Cmd []string `toml:"cmd"`
}

// GistConfig is a struct of config for Gist
Expand Down

0 comments on commit 803bc98

Please sign in to comment.