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

Automate Yo' Self -- SeaGL 2016

Automate Yo' Self -- SeaGL 2016

A talk about personal automation, as delivered at SeaGL on 12 Nov 2016

John SJ Anderson

November 12, 2016
Tweet

More Decks by John SJ Anderson

Other Decks in Programming

Transcript

  1. Job

  2. % cat ~/.mise --- manage: - doc - etc -

    private - proj/* - src/* create: directories: - bin - proj - proj/go/src/github.com/genehack - src - var links: - Desktop: var/tmp - Desktop: tmp
  3. % cat proj/emacs/.mise --- create: links: - DIR: ~/.emacs.d -

    bin/build-most-recent-emacs: BIN - bin/e: BIN - bin/ec: BIN - bin/git-blame-from-line-num: BIN - bin/map-test-lib: BIN
  4. % mise [LINK] created ~/proj/emacs -> ~/.emacs.d [LINK] created ~/proj/emacs/bin/build-most-recent-emacs

    -> ~/bin/build-most-recent-emacs [LINK] created ~/proj/emacs/bin/e -> ~/bin/e [LINK] created ~/proj/emacs/bin/ec -> ~/bin/ec [LINK] created ~/proj/emacs/bin/git-blame-from-line-num -> ~/bin/git-blame-from-line-num [LINK] created ~/proj/emacs/bin/map-test-lib -> ~/bin/map-test-lib % mise % rm ~/bin/e % mise [LINK] created ~/proj/emacs/bin/e -> ~/bin/e
  5. % smartcd show enter /Users/genehack/.smartcd/scripts/Users/genehack/fake-node-proj/bash_enter exists ------------------------------------------------------------------------- ######################################################################## # smartcd

    enter - /Users/genehack/fake-node-proj # # This is a smartcd script. Commands you type will be run when you # enter this directory. The string __PATH__ will be replaced with # the current path. Some examples are editing your $PATH or creating # a temporary alias: # # autostash PATH=__PATH__/bin:$PATH # autostash alias restart="service stop; sleep 1; service start" # # See http://smartcd.org for more ideas about what can be put here ######################################################################## autostash NODE=4.2.3 autostash PATH=$PATH:__PATH__/node_modules/.bin/ nvm use $NODE -------------------------------------------------------------------------
  6. % smartcd show enter /Users/genehack/.smartcd/scripts/Users/genehack/fake-node-proj/bash_enter exists ------------------------------------------------------------------------- ######################################################################## # smartcd

    enter - /Users/genehack/fake-node-proj # # This is a smartcd script. Commands you type will be run when you # enter this directory. The string __PATH__ will be replaced with # the current path. Some examples are editing your $PATH or creating # a temporary alias: # # autostash PATH=__PATH__/bin:$PATH # autostash alias restart="service stop; sleep 1; service start" # # See http://smartcd.org for more ideas about what can be put here ######################################################################## autostash NODE=4.2.3 autostash PATH=$PATH:__PATH__/node_modules/.bin/ nvm use $NODE -------------------------------------------------------------------------
  7. % smartcd show enter /Users/genehack/.smartcd/scripts/Users/genehack/fake-node-proj/bash_enter exists ------------------------------------------------------------------------- ######################################################################## # smartcd

    enter - /Users/genehack/fake-node-proj # # This is a smartcd script. Commands you type will be run when you # enter this directory. The string __PATH__ will be replaced with # the current path. Some examples are editing your $PATH or creating # a temporary alias: # # autostash PATH=__PATH__/bin:$PATH # autostash alias restart="service stop; sleep 1; service start" # # See http://smartcd.org for more ideas about what can be put here ######################################################################## autostash NODE=4.2.3 autostash PATH=$PATH:__PATH__/node_modules/.bin/ nvm use $NODE -------------------------------------------------------------------------
  8. % cd ~/fake-node-proc Now using node v4.2.3 (npm v2.14.7) %

    echo xx$NODE xx4.2.3 % cd .. % echo xx$NODE xx
  9. $ cd ~/my_project $ echo ${FOO-nope} nope $ echo export

    FOO=foo > .envrc .envrc is not allowed $ direnv allow . direnv: reloading direnv: loading .envrc direnv export: +FOO $ echo ${FOO-nope} foo $ cd .. direnv: unloading direnv export: ~FOO $ echo ${FOO-nope} nope
  10. $ cd ~/my_project $ echo ${FOO-nope} nope $ echo export

    FOO=foo > .envrc .envrc is not allowed $ direnv allow . direnv: reloading direnv: loading .envrc direnv export: +FOO $ echo ${FOO-nope} foo $ cd .. direnv: unloading direnv export: ~FOo $ echo ${FOO-nope} nope
  11. $ cd ~/my_project $ echo ${FOO-nope} nope $ echo export

    FOO=foo > .envrc .envrc is not allowed $ direnv allow . direnv: reloading direnv: loading .envrc direnv export: +FOO $ echo ${FOO-nope} foo $ cd .. direnv: unloading direnv export: ~FOO $ echo ${FOO-nope} nope
  12. ag!

  13. - name: App-Amylase path: /Users/genehack/proj/App-Amylase repo: [email protected]:genehack/App-Amylase.git type: git -

    name: Git-Wrapper path: /Users/genehack/proj/Git-Wrapper repo: [email protected]:genehack/Git-Wrapper.git tags: git type: git - name: HiD path: /Users/genehack/proj/HiD repo: [email protected]:genehack/HiD.git type: git - name: Perl-Build path: /opt/plenv/plugins/perl-build repo: git://github.com/tokuhirom/Perl-Build.git type: git
  14. 1) App-Amylase git [email protected]:genehack/App-Amylase.git 2) Git-Wrapper git [email protected]:genehack/Git-Wrapper.git 3) HiD

    git [email protected]:genehack/HiD.git 4) Perl-Build git git://github.com/tokuhirom/Perl-Build.git 5) Perl-Critic git [email protected]:genehack/Perl-Critic.git 6) STAMPS git [email protected]:genehack/STAMPS.git 7) advanced-moose-class git ssh://[email protected]/train/advanced-moose-class.git 8) app-gitgitr git [email protected]:genehack/app-gitgitr.git 9) app-gitgot git [email protected]:genehack/app-gitgot.git
  15. 1) App-Amylase 2) Git-Wrapper 3) HiD 4) Perl-Build 5) Perl-Critic

    6) STAMPS 7) advanced-moose-class 8) app-gitgitr 9) app-gitgot
  16. 1) App-Amylase : OK 2) Git-Wrapper : OK 3) HiD

    : OK 4) Perl-Build : OK 5) Perl-Critic : OK 6) STAMPS : OK 7) advanced-moose-class : OK 8) app-gitgitr : OK 9) app-gitgot : OK
  17. 1) App-Amylase : OK 2) Git-Wrapper : OK 3) HiD

    : Dirty 4) Perl-Build : OK 5) Perl-Critic : OK 6) STAMPS : OK 7) advanced-moose-class : OK 8) app-gitgitr : OK 9) app-gitgot : OK Dirty
  18. 1) App-Amylase : OK 2) Git-Wrapper : OK 3) HiD

    : OK 4) Perl-Build : OK 5) Perl-Critic : OK 6) STAMPS : OK Ahead by 1 7) advanced-moose-class : OK 8) app-gitgitr : OK 9) app-gitgot : OK 1) App-Amylase : OK 2) Git-Wrapper : OK 3) HiD : OK 4) Perl-Build : Dirty 5) Perl-Critic : OK 6) STAMPS : OK 7) advanced-moose-class : OK 8) app-gitgitr : OK 9) app-gitgot : OK Dirty 1) App-Amylase : OK 2) Git-Wrapper : OK 3) HiD : OK 4) Perl-Build : OK 5) Perl-Critic : OK 6) STAMPS : OK Ahead by 1 7) advanced-moose-class : OK 8) app-gitgitr : OK 9) app-gitgot : OK Ahead by 1
  19. got st -q 3) HiD : Dirty 6) STAMPS :

    OK Ahead by 1 Dirty Ahead by 1
  20. 1) App-Amylase : Up to date 2) Git-Wrapper : Up

    to date 3) HiD : Up to date 4) Perl-Build : Updated Updating 7f25f89..72587c8 Fast-forward lib/Perl/Build.pm | 14 +++++++++++++- script/perl-build | 14 +++++++++++++- 2 files changed, 26 insertions(+), 2 deletions(-) 5) Perl-Critic : Up to date Updated
  21. package App::GitGot::Command::chdir; # ABSTRACT: open a subshell in a selected

    project use 5.014; use App::GitGot -command; use Moo; extends 'App::GitGot::Command'; use namespace::autoclean; sub command_names { qw/ chdir cd / } sub _execute { my( $self, $opt, $args ) = @_; unless ( $self->active_repos and $self->active_repos == 1 ) { say STDERR 'ERROR: You need to select a single repo'; exit(1); } my( $repo ) = $self->active_repos; chdir $repo->path or say STDERR "ERROR: Failed to chdir to repo ($!)" and exit(1); exec $ENV{SHELL}; } 1;
  22. sub _execute { my( $self, $opt, $args ) = @_;

    unless ( $self->active_repos and $self->active_repos == 1 ) { say STDERR 'ERROR: You need to select a single repo'; exit(1); } my( $repo ) = $self->active_repos; chdir $repo->path or say STDERR "ERROR: Failed to chdir to repo ($!)" and exit(1); exec $ENV{SHELL}; }
  23. package App::GitGot::Command::chdir; # ABSTRACT: open a subshell in a selected

    project use 5.014; use App::GitGot -command; use Moo; extends 'App::GitGot::Command'; use namespace::autoclean; sub command_names { qw/ chdir cd / } sub _execute { my( $self, $opt, $args ) = @_; unless ( $self->active_repos and $self->active_repos == 1 ) { say STDERR 'ERROR: You need to select a single repo'; exit(1); } my( $repo ) = $self->active_repos; chdir $repo->path or say STDERR "ERROR: Failed to chdir to repo ($!)" and exit(1); exec $ENV{SHELL}; } 1;
  24. …but it is a great way to learn a new

    language You don't have to write a code…