Modify `$` prompt (or print information on each script step)

Hello Travis, I’m a big fan (!) Long time builder, first time poster. :stuck_out_tongue:

I don’t know if there’s a way to do what I want already or not. But I’d like to customize the $ which prefixes script commands with a custom prompt. For instance: I have a config environment variable NUMBER which helps identify the build in the matrix, and rather than seeing:

$ some command

It would be very useful to me if it could say, e.g.:

#3 $ some command

That would make it easier to go quickly between being in the middle of reading a log file and then to switch over to editing the .travis.yml for that build. (In my case, the other parameters are subtle permutations that it takes time to scan and absorb and make the connection.)

I tried setting the PS1 environment variable, but it seemed to be ignored. I gather Travis is just printing that dollar sign literally somewhere.

Is there any way to configure this, or to get an equivalent “small piece of information output automatically with every step”? (If someone does figure out how to do this, it would be helpful if they could demonstrate it literally with my case–putting the # sign in the prompt–because I’m also getting a situation where # in the YAML is being interpreted as a comment even when inside a string. )

Thanks!

The $ <command> line is printed by the travis_cmd shell function that’s located in the autogenerated $HOME/.travis/job_stages and is available in the running shell’s environment. You can redefine it, though wrapping shell functions is not very straightforward…

But there’s probably a better way to do whatever you’re trying to do since your use case is not very convincing: Travis already folds every command’s output after it has finished executing, and the “$<space>” string is sufficiently rare in normal output to quick search by it to navigate the log.

Thanks for the pointer to the travis_cmd shell function…

…but I’m afraid I don’t understand what you mean by this. I am interested in being at an arbitrary location in a very long output log, and without having to change my scroll position from what I’m reading, know which build number it is.

As I mentioned, NUMBER= is the first build setting in the configuration. It is not a matter of not being able to find it, I could do so with “Ctrl F” and then “NUMBER=” and the log would jump to another location and I could see which build I was on. But then I’d have to navigate back to where I was before the jump, read the output I was scrutinizing again, side to side with the yaml file at the point I want to edit it.

It’s a matter of contextualizing more quickly so I really just go from seeing the problem to Alt-Tab to the editor and know exactly which matrix setting to change.

You can duplicate the browser tab with the log (Firefox and Chrome at least can do this out of the box) and keep the duplicate at the settings section.

I also use the following trick to quickly return to the current position: select & copy a unique enough chunk of text around it, then after going elsewhere, quick search for it.

At the moment, $ is fully hard coded (without $PS1). It is not impossible to change what is written to the logs, but it would be deep into the implementation details of our build script, and I would not recommend it.