0

I am creating a bash script which I wish to release on github. The script needs to access the command history but this is not possible without sourcing that script.

I don't want users to put it in their ~/.bashrc or source the script every time they run it.

So, is there any way I can create a script which gets sourced by default.

Alternatively...

Is there some way to access the history of the current terminal without sourcing the script?

  • If you don't want users to "source the script every time they run it", then when do you want them to source it? Once only right after they clone it from github? I'm not sure I understand, but I guess you could define a shell function which users invoke thereafter? – Celada Jan 24 '15 at 9:05
1

If the script needs to access the history, insert an alias into the .bashrc. I have this for the command auto which has an option to repeat the latest command, ad infinitum, depending on changes in the provided commandline arguments.

The alias:

auto = 'history | auto'

Assuming that some_command_to_test depends on input.py and output.py I use this to first run the command once, then repeatedly (while changing input.py and output.py in some other window:

$ some_command_to_test arg1 arg2 arg3
$ auto -l input.py output.py

In the program (in my case auto) just read through the stdin to find the appropriate information ( I take the last command that doesn't involve auto itself, so I can stop auto and restart it without auto-ing auto itself).

This way there is no need to repeatedly source a script.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.