I added logging the terminal output to txt file, and this is enabled via a function in .bashrc
:
start_terminal_logging()
{
if [ -z "$SCRIPT_LOG_FILE_ACTIVE" ]; then
# Log each session to a separate file:
logdir=~/.terminal_logs
logfile=$logdir/session_log_$(date +%Y%m%d_%H%M%S)_$$.txt
# If no folder exist make one:
if [ ! -d $logdir ]; then
mkdir -p $logdir
fi
export SCRIPT_LOG_FILE_ACTIVE=$logfile
# Start logging, a=append, q=quiet:
script -aq $logfile
exit
fi
}
# Start the logging(script above):
start_terminal_logging
This worked in normal bash terminal, but not in the VS Code terminal, so I moddified user’s settings.json
to reset the variable which was causing problems to VS Code (it was inherited from the environment I guss, so I reset it):
"terminal.integrated.env.linux": {
"SCRIPT_LOG_FILE_ACTIVE": null,
}
This worked, and now logging from VS Code terminal is OK too, however, after I added this, the Conda evnironment is not automatically started in VS Code as it used to. What could be the problem?
5
Your question is not clear as written, so I’m not entirely sure what you’re after. That said, the issue might be a problem between interactive vs. non-interactive shells.
When Bash runs a full interactive login shell, it normally executes ~/.bash_login
, and when it runs non-interactively (such as from a crontab, or other background process) it sources ~/.bashrc
. This is why you shouldn’t include text output in your ~/.bashrc
, or it may end up in some random log file for a background process!
If your issue is that you don’t want your script to run for these background processes, but you do want it to run on a regular login shell, just put your code into ~/.bash_login
and you’re done.
If this doesn’t solve it, please explain the problem more specifically.