mirror of https://github.com/curusarn/resh
parent
583224527f
commit
82a40f7f29
@ -0,0 +1,48 @@ |
||||
package cmd |
||||
|
||||
import ( |
||||
"os" |
||||
|
||||
"github.com/curusarn/resh/cmd/control/status" |
||||
"github.com/spf13/cobra" |
||||
) |
||||
|
||||
// completionCmd represents the completion command
|
||||
var completionCmd = &cobra.Command{ |
||||
Use: "completion", |
||||
Short: "Generates bash/zsh completion scripts", |
||||
Long: `To load completion run |
||||
|
||||
. <(reshctl completion bash)
|
||||
|
||||
OR
|
||||
|
||||
. <(reshctl completion zsh)
|
||||
`, |
||||
} |
||||
|
||||
var completionBashCmd = &cobra.Command{ |
||||
Use: "bash", |
||||
Short: "Generates bash completion scripts", |
||||
Long: `To load completion run |
||||
|
||||
. <(reshctl completion bash)
|
||||
`, |
||||
Run: func(cmd *cobra.Command, args []string) { |
||||
rootCmd.GenBashCompletion(os.Stdout) |
||||
exitCode = status.Success |
||||
}, |
||||
} |
||||
|
||||
var completionZshCmd = &cobra.Command{ |
||||
Use: "zsh", |
||||
Short: "Generates zsh completion scripts", |
||||
Long: `To load completion run |
||||
|
||||
. <(reshctl completion zsh)
|
||||
`, |
||||
Run: func(cmd *cobra.Command, args []string) { |
||||
rootCmd.GenZshCompletion(os.Stdout) |
||||
exitCode = status.Success |
||||
}, |
||||
} |
||||
@ -0,0 +1,24 @@ |
||||
package cmd |
||||
|
||||
import ( |
||||
"github.com/curusarn/resh/cmd/control/status" |
||||
"github.com/spf13/cobra" |
||||
) |
||||
|
||||
var disableCmd = &cobra.Command{ |
||||
Use: "disable", |
||||
Short: "disable RESH features", |
||||
Long: `Disables RESH bindings for arrows and C-R.`, |
||||
Run: func(cmd *cobra.Command, args []string) { |
||||
exitCode = status.DisableAll |
||||
}, |
||||
} |
||||
|
||||
// var disableRecallingCmd = &cobra.Command{
|
||||
// Use: "keybind",
|
||||
// Short: "Disables RESH bindings for arrows and C-R.",
|
||||
// Long: `Disables RESH bindings for arrows and C-R.`,
|
||||
// Run: func(cmd *cobra.Command, args []string) {
|
||||
// exitCode = status.DisableAll
|
||||
// },
|
||||
// }
|
||||
@ -0,0 +1,24 @@ |
||||
package cmd |
||||
|
||||
import ( |
||||
"github.com/curusarn/resh/cmd/control/status" |
||||
"github.com/spf13/cobra" |
||||
) |
||||
|
||||
var enableCmd = &cobra.Command{ |
||||
Use: "enable", |
||||
Short: "enable RESH features", |
||||
Long: `Enables RESH bindings for arrows and C-R.`, |
||||
Run: func(cmd *cobra.Command, args []string) { |
||||
exitCode = status.EnableAll |
||||
}, |
||||
} |
||||
|
||||
// var enableRecallingCmd = &cobra.Command{
|
||||
// Use: "keybind",
|
||||
// Short: "Enables RESH bindings for arrows and C-R.",
|
||||
// Long: `Enables RESH bindings for arrows and C-R.`,
|
||||
// Run: func(cmd *cobra.Command, args []string) {
|
||||
// exitCode = status.EnableAll
|
||||
// },
|
||||
// }
|
||||
@ -0,0 +1,39 @@ |
||||
package cmd |
||||
|
||||
import ( |
||||
"fmt" |
||||
"log" |
||||
|
||||
"github.com/curusarn/resh/cmd/control/status" |
||||
"github.com/spf13/cobra" |
||||
) |
||||
|
||||
var exitCode status.Code = status.DefaultInvalid |
||||
|
||||
var rootCmd = &cobra.Command{ |
||||
Use: "reshctl", |
||||
Short: "Reshctl (RESH control) - enables you to enable/disable features and more.", |
||||
Long: `Enables you to enable/disable RESH bindings for arrows and C-R.`, |
||||
} |
||||
|
||||
// Execute reshctl
|
||||
func Execute() status.Code { |
||||
rootCmd.AddCommand(disableCmd) |
||||
// disableCmd.AddCommand(disableRecallingCmd)
|
||||
|
||||
rootCmd.AddCommand(enableCmd) |
||||
// enableCmd.AddCommand(enableRecallingCmd)
|
||||
|
||||
rootCmd.AddCommand(completionCmd) |
||||
completionCmd.AddCommand(completionBashCmd) |
||||
completionCmd.AddCommand(completionZshCmd) |
||||
if err := rootCmd.Execute(); err != nil { |
||||
fmt.Println(err) |
||||
return status.Fail |
||||
} |
||||
if exitCode == status.DefaultInvalid { |
||||
log.Println("reshctl FATAL ERROR: (sub)command didn't set exitCode!") |
||||
return status.Fail |
||||
} |
||||
return exitCode |
||||
} |
||||
@ -0,0 +1,17 @@ |
||||
package main |
||||
|
||||
import ( |
||||
"os" |
||||
|
||||
"github.com/curusarn/resh/cmd/control/cmd" |
||||
) |
||||
|
||||
// Version from git set during build
|
||||
var Version string |
||||
|
||||
// Revision from git set during build
|
||||
var Revision string |
||||
|
||||
func main() { |
||||
os.Exit(int(cmd.Execute())) |
||||
} |
||||
@ -0,0 +1,17 @@ |
||||
package status |
||||
|
||||
// Code - exit code of the resh-control command
|
||||
type Code int |
||||
|
||||
const ( |
||||
// DefaultInvalid exit code
|
||||
DefaultInvalid Code = -1 |
||||
// Success exit code
|
||||
Success = 0 |
||||
// Fail exit code
|
||||
Fail = 1 |
||||
// EnableAll exit code - tells reshctl() wrapper to enable_all
|
||||
EnableAll = 100 |
||||
// DisableAll exit code - tells reshctl() wrapper to disable_all
|
||||
DisableAll = 110 |
||||
) |
||||
@ -1,19 +1,49 @@ |
||||
github.com/BurntSushi/toml v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ= |
||||
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= |
||||
github.com/armon/consul-api v0.0.0-20180202201655-eb2c6b5be1b6/go.mod h1:grANhF5doyWs3UAsr3K4I6qtAmlQcZDesFNEHPZAzj8= |
||||
github.com/coreos/etcd v3.3.10+incompatible/go.mod h1:uF7uidLiAD3TWHmW31ZFd/JWoc32PjwdhPthX9715RE= |
||||
github.com/coreos/go-etcd v2.0.0+incompatible/go.mod h1:Jez6KQU2B/sWsbdaef3ED8NzMklzPG4d5KIOhIy30Tk= |
||||
github.com/coreos/go-semver v0.2.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3EedlOD2RNk= |
||||
github.com/cpuguy83/go-md2man v1.0.10/go.mod h1:SmD6nW6nTyfqj6ABTjUi3V3JVMnlJmwcJI5acqYI6dE= |
||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= |
||||
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= |
||||
github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0 h1:DACJavvAHhabrF08vX0COfcOBJRhZ8lUbR+ZWIs0Y5g= |
||||
github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0/go.mod h1:E/TSTwGwJL78qG/PmXZO1EjYhfJinVAhrmmHX6Z8B9k= |
||||
github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ= |
||||
github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8= |
||||
github.com/jpillora/longestcommon v0.0.0-20161227235612-adb9d91ee629 h1:1dSBUfGlorLAua2CRx0zFN7kQsTpE2DQSmr7rrTNgY8= |
||||
github.com/jpillora/longestcommon v0.0.0-20161227235612-adb9d91ee629/go.mod h1:mb5nS4uRANwOJSZj8rlCWAfAcGi72GGMIXx+xGOjA7M= |
||||
github.com/magiconair/properties v1.8.0/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ= |
||||
github.com/mattn/go-shellwords v1.0.6 h1:9Jok5pILi5S1MnDirGVTufYGtksUs/V2BWUP3ZkeUUI= |
||||
github.com/mattn/go-shellwords v1.0.6/go.mod h1:3xCvwCdWdlDJUrvuMn7Wuy9eWs4pE8vqg+NOMyg4B2o= |
||||
github.com/mb-14/gomarkov v0.0.0-20190125094512-044dd0dcb5e7 h1:VsJjhYhufMGXICLwLYr8mFVMp8/A+YqmagMHnG/BA/4= |
||||
github.com/mb-14/gomarkov v0.0.0-20190125094512-044dd0dcb5e7/go.mod h1:zQmHoMvvVJb7cxyt1wGT77lqUaeOFXlogOppOr4uHVo= |
||||
github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0= |
||||
github.com/mitchellh/mapstructure v1.1.2/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y= |
||||
github.com/pelletier/go-toml v1.2.0/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/94hg7ilaic= |
||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= |
||||
github.com/russross/blackfriday v1.5.2/go.mod h1:JO/DiYxRf+HjHt06OyowR9PTA263kcR/rfWxYHBV53g= |
||||
github.com/schollz/progressbar v1.0.0 h1:gbyFReLHDkZo8mxy/dLWMr+Mpb1MokGJ1FqCiqacjZM= |
||||
github.com/schollz/progressbar v1.0.0/go.mod h1:/l9I7PC3L3erOuz54ghIRKUEFcosiWfLvJv+Eq26UMs= |
||||
github.com/spf13/afero v1.1.2/go.mod h1:j4pytiNVoe2o6bmDsKpLACNPDBIoEAkihy7loJ1B0CQ= |
||||
github.com/spf13/cast v1.3.0/go.mod h1:Qx5cxh0v+4UWYiBimWS+eyWzqEqokIECu5etghLkUJE= |
||||
github.com/spf13/cobra v0.0.5 h1:f0B+LkLX6DtmRH1isoNA9VTtNUK9K8xYd28JNNfOv/s= |
||||
github.com/spf13/cobra v0.0.5/go.mod h1:3K3wKZymM7VvHMDS9+Akkh4K60UwM26emMESw8tLCHU= |
||||
github.com/spf13/jwalterweatherman v1.0.0/go.mod h1:cQK4TGJAtQXfYWX+Ddv3mKDzgVb68N+wFjFa4jdeBTo= |
||||
github.com/spf13/pflag v1.0.3 h1:zPAT6CGy6wXeQ7NtTnaTerfKOsV6V6F8agHXFiazDkg= |
||||
github.com/spf13/pflag v1.0.3/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4= |
||||
github.com/spf13/viper v1.3.2/go.mod h1:ZiWeW+zYFKm7srdB9IoDzzZXaJaI5eL9QjNiN/DMA2s= |
||||
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= |
||||
github.com/ugorji/go/codec v0.0.0-20181204163529-d75b2dcb6bc8/go.mod h1:VFNgLljTbGfSG7qAOspJ7OScBnGdDN/yBr0sguwnwf0= |
||||
github.com/wcharczuk/go-chart v2.0.1+incompatible h1:0pz39ZAycJFF7ju/1mepnk26RLVLBCWz1STcD3doU0A= |
||||
github.com/wcharczuk/go-chart v2.0.1+incompatible/go.mod h1:PF5tmL4EIx/7Wf+hEkpCqYi5He4u90sw+0+6FhrryuE= |
||||
github.com/whilp/git-urls v0.0.0-20160530060445-31bac0d230fa h1:rW+Lu6281ed/4XGuVIa4/YebTRNvoUJlfJ44ktEVwZk= |
||||
github.com/whilp/git-urls v0.0.0-20160530060445-31bac0d230fa/go.mod h1:2rx5KE5FLD0HRfkkpyn8JwbVLBdhgeiOb2D2D9LLKM4= |
||||
github.com/xordataexchange/crypt v0.0.3-0.20170626215501-b2862e3d0a77/go.mod h1:aYKd//L2LvnjZzWKhF00oedf4jCCReLcmhLdhm1A27Q= |
||||
golang.org/x/crypto v0.0.0-20181203042331-505ab145d0a9/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= |
||||
golang.org/x/image v0.0.0-20190902063713-cb417be4ba39 h1:4dQcAORh9oYBwVSBVIkP489LUPC+f1HBkTYXgmqfR+o= |
||||
golang.org/x/image v0.0.0-20190902063713-cb417be4ba39/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0= |
||||
golang.org/x/sys v0.0.0-20181205085412-a5c9d58dba9a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= |
||||
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= |
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= |
||||
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= |
||||
|
||||
@ -0,0 +1,37 @@ |
||||
|
||||
|
||||
# shellcheck source=../submodules/bash-zsh-compat-widgets/bindfunc.sh |
||||
. ~/.resh/bindfunc.sh |
||||
# shellcheck source=widgets.sh |
||||
. ~/.resh/widgets.sh |
||||
|
||||
__resh_bind_arrows() { |
||||
echo "bindfunc __resh_widget_arrow_up" |
||||
echo "bindfunc __resh_widget_arrow_down" |
||||
return 0 |
||||
} |
||||
|
||||
__resh_bind_control_R() { |
||||
echo "bindfunc __resh_widget_control_R" |
||||
return 0 |
||||
} |
||||
__resh_unbind_arrows() { |
||||
echo "\ bindfunc __resh_widget_arrow_up" |
||||
echo "\ bindfunc __resh_widget_arrow_down" |
||||
return 0 |
||||
} |
||||
|
||||
__resh_unbind_control_R() { |
||||
echo "\ bindfunc __resh_widget_control_R" |
||||
return 0 |
||||
} |
||||
|
||||
__resh_bind_all() { |
||||
__resh_bind_arrows |
||||
__resh_bind_control_R |
||||
} |
||||
|
||||
__resh_unbind_all() { |
||||
__resh_unbind_arrows |
||||
__resh_unbind_control_R |
||||
} |
||||
@ -0,0 +1,33 @@ |
||||
|
||||
# source bindutil - contains functions to bind and unbind RESH widgets |
||||
# shellcheck source=bindutil.sh |
||||
. ~/.resh/bindutil.sh |
||||
|
||||
reshctl() { |
||||
# run resh-control aka the real reshctl |
||||
resh-control "$@" |
||||
# modify current shell session based on exit status |
||||
local status=$? |
||||
case "$status" in |
||||
0|1) |
||||
# success | fail |
||||
return "$status" |
||||
;; |
||||
# enable |
||||
100) |
||||
# enable all |
||||
__resh_bind_all |
||||
return 0 |
||||
;; |
||||
# disable |
||||
110) |
||||
# disable all |
||||
__resh_unbind_all |
||||
return 0 |
||||
;; |
||||
*) |
||||
echo "reshctl() FATAL ERROR: unknown status" >&2 |
||||
return "$status" |
||||
;; |
||||
esac |
||||
} |
||||
@ -0,0 +1,10 @@ |
||||
|
||||
__resh_widget_arrow_up() { |
||||
return 0 |
||||
} |
||||
__resh_widget_arrow_down() { |
||||
return 0 |
||||
} |
||||
__resh_widget_control_R() { |
||||
return 0 |
||||
} |
||||
Loading…
Reference in new issue