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

212c3e1fd2d20c085013626e12d157a6?s=128

Yusuke Komatsu

November 05, 2019
Tweet

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. None
  5. None
  6. Create shell manager with golang Photo by Ilya Pavlov on

    Unsplash creating
  7. https://github.com/getshway/shway

  8. Origin of name (public stance) sh(ell) + way = shway

  9. Origin of name SCHWAY!! DC Comic The flash

  10. Motivation

  11. Motivation Change default shell to zsh

  12. Motivation

  13. Motivation How to manage dotfiles?

  14. Motivation

  15. Motivation

  16. Motivation Can I use Homebrew on future Mac?

  17. Motivation

  18. Motivation

  19. Motivation How to share development environment?

  20. Motivation Join a new project

  21. Motivation Join a new project Get ready in 40 seconds!

  22. Motivation development environment ↓ as shell scripts ↓ manage with

    git ↓ get from git repos ↓ we can share!!
  23. What’s SHWAY !?

  24. What’s SHWAY !? milestone • manage dot files • manage

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

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

    sets a project (dotfiles) from github $ shway set foobar git@github.com: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 ...
  27. I thought I could create 2 days But I couldn’t

  28. 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
  29. 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
  30. 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)
  31. 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/
  32. 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
  33. 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) }
  34. Awesome packages https://github.com/src-d/go-git

  35. Awesome packages https://github.com/src-d/go-git

  36. Awesome packages https://github.com/spf13/cobra

  37. 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
  38. Thank you ϦϦʔεͰ͖ͨΒ Ͳ͔ͬͷLTͰ ใࠂ͍ͤͯͩ͘͞͞