Jump to content

[SOLVED] Help with trying to use shell command in `Run Script` object


Recommended Posts

I have this workflow originally made by @vitor and modified by me.

 

It is messy but it works for nearly everything I need it to do. Except one thing. 

 

939560746_2018-05-14at20_23.png.309bbab5682214972cd504ce74b5e46d.png

 

This script tries to run inside it `hub fork`. I have downloaded hub on my system. And I give the full path to hub like so: /usr/local/bin/hub.

 

This fails for me and doesn't actually do the fork. If I run the same command in my terminal however, the command works perfectly well.

 

The debugger shows this when I run it:

 

[2018-05-14 20:31:17][input.scriptfilter] Processing output of 'action.script' with arg '/Users/nikivi/dev/clones/subliminal'

[2018-05-14 20:31:17][ERROR: action.script] Error forking repository: Unauthorized (HTTP 401)

Requires authentication

fatal: Not a git repository (or any of the parent directories): .git

fatal: Not a git repository (or any of the parent directories): .git

fatal: Not a git repository (or any of the parent directories): .git

 

I suppose it is because Alfred doesn't see my GitHub credentials attached to my Git config but I am not sure how I can solve this, if I can.

 

The purpose of this this object is that after I scan my ~/dev/clones directory and get a list of different repos there, I run an action and it forks the repository using `hub fork` command and then moves the repo from ~/dev/clones to ~/dev/forks. The moving part works, it's the forking that doesn't.

 

Thank you for any help.

Edited by nikivi
Link to comment

Yay. It now forks the repo. 

 

However a strange thing happens where the AppleScript that should then cd into the directory I moved to ~/dev/forks doesn't do that. 

 

It prints: cd Updating new remote: ~/dev/forks/bat && exanikitavoloboevnikitavoloboev instead of `cd ~/dev/forks/bat && exa

 

It's strange because I thought that Bash should run things one after another. So it should wait until hub fork finishes doing its thing. And then runs the other stuff like moving the directory, running the two git commands I do: 

#/usr/local/bin/hub branch --set-upstream-to nikitavoloboev/master master
#/usr/local/bin/hub remote rename origin upstream; git remote rename nikitavoloboev origin

 

And then I echo the path of where the fork now should lie with:

echo "~/dev/forks/$CLONE_DIR_NAME"

 

The only thing I did change was to add source ~/.zshrc at the top of the Run Script object. Here is the updated workflow.

 

Here is what I get in debugger when I run the action.

 

Should I perhaps put some pauses in the bash script? It already runs slower than I would like it to presumingly because of me sourcing my entire shell env.

 

Edited by nikivi
Link to comment

Now that it’s confirmed, what you should do is remove the source, figure out what in that file is allowing hub to work, and copy over just that. Or better yet, remove whatever it is until hub breaks in your shell and asks to be configured again, this time into ~/.config/hub.


For reference, its config is something like:

github.com:
- user: username
  oauth_token: 4c0f1f3023d42e7be5fdb86264aa9cbc02ec5d4b
  protocol: https

Edited by vitor
Link to comment

Never mind all this. I solved it by simply running these `hub` commands in iTerm by creating a zsh function and calling that in iTerm.

 

Zsh function:

 

# Fork cloned repo
gfr(){
  hub fork
  git branch --set-upstream-to nikitavoloboev/master master
  git remote rename origin upstream; git remote rename nikitavoloboev origin
}

 

And I just made AppleScript run the commands in succession like so:

 

❯ cd ~/dev/forks/codehn && gfr && exa

 

Here is the final workflow in the odd chance anyone wants to use it. ?

 

Thank you very much @vitor

 

Link to comment
  • vitor changed the title to [SOLVED] Help with trying to use shell command in `Run Script` object

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...