1

Suppose I execute a command which prompts the user for input. Is there a way by which I can pass the input in the command itself, rather than taking the input from the user. Like for example, in cloning a private github repo I type:

!git clone https://github.com/username/repo.git

instead I want to do something like

!echo "username" | git clone https://github.com/username/repo.git.

Instead of echo can I have something which automatically inputs username when prompted, by reading it from a file or specifying it directly in my command?

Thanks for helping!

1 Answer 1

0

I'm assuming you're using exclamation points (!) as a prompt indicator. That seems counterintuitive, but otherwise they are instructions to your command-line shell that you want to complete to the most recent command that matches that prefix.

Passing data to another program requires knowing how that program expects data. I'm not sure git has a reliable way to do this given the https:// notation (it might support the legacy HTTP authentication method of https://user:password@host/path, but I do not recommend that). If you switch to using ssh:// notation, you can do it with git clone ssh://[email protected]/…/repo.git … but Github doesn't work with usernames that way; it always uses the same user (git) and it identifies Github users by their SSH key. This is completely automatic (no changes needed to the command line); just run git clone ssh://github.com/githubuser/repo.git after following Github's solid documentation.


If you're looking for a way to support multiple Github accounts, you may be interested in a Userscript I wrote for that exact purpose:

https://github.com/adamhotep/userscripts/blob/main/Github - UI Tweaks.user.js

This changes Github's interface to allow toggling between SSH keys that identify different accounts. Once it is set up, all you have to do is select the right item from the <> Code dialog for cloning. (It is self-documented; for instructions, click the 👥 button next to the ? button in that same dialog.)

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.