Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Create shell manager with golang

Create shell manager with golang

slide for golang.tokyo#27

Yusuke Komatsu

November 05, 2019
Tweet

More Decks by Yusuke Komatsu

Other Decks in Programming

Transcript

  1. Create shell manager with golang Photo by Ilya Pavlov on

    Unsplash Yusuke Komatsu GitHub: usk81
  2. Create shell manager with golang Photo by Ilya Pavlov on

    Unsplash Yusuke Komatsu GitHub: usk81 creating
  3. { "basics": { "name": "Yusuke Komatsu" }, "skills": [ {"name":

    "Data Analyst"}, {"name": "Web Development"} ], "works": [ {"company": "Persol Process & Technology"}, ], "interests": [ {"name": "Fortnite"}, {"name": "Coffee"}, {"name": "Machine Learning"} ] } About Me:
  4. Motivation development environment ↓ as shell scripts ↓ manage with

    git ↓ get from git repos ↓ we can share!!
  5. What’s SHWAY !? milestone • manage dot files • manage

    homebrew and cask • manage ssh config • install homebrew and dependency packages when initialize shway
  6. What’s SHWAY !? current features
 •manage your •dot files •homebrew

    and cask •manage your team •dot files •homebrew and cask
  7. What’s SHWAY !? # initialize shway $ shway init #

    sets a project (dotfiles) from github $ shway set foobar [email protected]:getshway/sampleproject.git … # update a project and update/install homebrew and homebrew-cask $ shway update foobar Updated 5 taps (golangci/tap, homebrew/cask-versions, homebrew/core, homebrew/cask and homebrew/cask-fonts). ==> New Formulae awsume dvc govc grin grin-wallet javacc minikube navi nbdime ngt onefetch pnpm prestosql pylint tdkjs toast ttyplot wal2json ==> Updated Formulae ack ✔ borgmatic docfx gleam libphonenumber osquery s3ql terragrunt awscli ✔ botan docker glooctl librsvg paket salt terrahub dark-mode ✔ buku docker-completion gnuradio librsync pango saxon theharvester ...
  8. I couldn’t create 2days Change specification 1. Coding shell script

    shell script -> Golang Maybe, can not maintenance 2. source command is not work with Go 3. stdout is caught source command
  9. source command is not work with Go // golang //

    not work exec.Command("source", “something.sh").Run() // not work exec.Command("bash", "-c", "source", "something.sh").Run() 1SPDFTT TIXBZ 1SPDFTT TIFMM TPVSDF 1SPDFTT UFSNJOBM UBSHFUDVSSFOUQSPDFTT
  10. source command is not work with Go $ shway init

    shway() { case "$1" in init | load) source <( /usr/local/bin/shway $@ ) || /usr/local/bin/shway $@ ;; set | update) /usr/local/bin/shway $@ && source <( /usr/local/bin/shway load $2 ) || /usr/local/bin/shway $@ ;; *) /usr/local/bin/shway $@ ;; esac } _shway() { IFS=' ' read -A reply <<< "help set update load list init" } compctl -K _shway shway source /Users/usk/.shway/default/.alias source /Users/usk/.shway/default/.completions source /Users/usk/.shway/default/.functions source /Users/usk/.shway/default/.golang source /Users/usk/.shway/default/.history #.zshrc source <(shway init)
  11. refer. antibody $ antibody init #!/usr/bin/env zsh antibody() { case

    "$1" in bundle) source <( /usr/local/bin/antibody $@ ) || /usr/local/bin/antibody $@ ;; *) /usr/local/bin/antibody $@ ;; esac } _antibody() { IFS=' ' read -A reply <<< "help bundle update home purge list init" } compctl -K _antibody antibody #.zshrc source <(antibody init) https://getantibody.github.io/
  12. stdout is caught source command $ shway init shway() {

    case "$1" in init | load) source <( /usr/local/bin/shway $@ ) || /usr/local/bin/shway $@ ;; set | update) /usr/local/bin/shway $@ && source <( /usr/local/bin/shway load $2 ) || /usr/local/bin/ shway $@ ;; *) /usr/local/bin/shway $@ ;; esac } _shway() { IFS=' ' read -A reply <<< "help set update load list init" } compctl -K _shway shway source /Users/usk/.shway/default/.alias source /Users/usk/.shway/default/.completions source /Users/usk/.shway/default/.functions source /Users/usk/.shway/default/.golang source /Users/usk/.shway/default/.history update dot files and brews and install brews source dot files
  13. stdout is caught source command // Exit finishs requests func

    Exit(err error, codes ...int) { log.SetOutput(os.Stderr) log.SetPrefix("shway: ") log.SetFlags(0) var code int if len(codes) > 0 { code = codes[0] } else { code = 1 } log.Print(err.Error()) os.Exit(code) }
  14. Awesome packages package command import ( "fmt" "github.com/getshway/shway/initialize" "github.com/spf13/cobra" )

    var ( initCmd = &cobra.Command{ Use: "init", Short: "setup shway and load zsh config", Long: "setup shway and load zsh config", Run: initCommand, } ) func init() { RootCmd.AddCommand(initCmd) } func initCommand(cmd *cobra.Command, args []string) { out, err := initialize.Run() if err != nil { Exit(err, 1) } fmt.Println(out) } define as a use case command package