News for hackers. Stuff that matters.
Re:"Rules" that terminal programs follow by saghm on Thursday December 12, 2024 @04:25PM (#42403516)
I don't think it's part of the terminal emulator (e.g. xterm, gnome-terminal) but the shell (bash, zsh, etc.). You're correct that it's not something that's implemented as an external program though; the "current directory" is state for a currently running terminal session, so changing that state is done via the shell interface (either directly by built-in commands like cd or indirectly via external commands that use those transitively).
Re:"Rules" that terminal programs follow by machinestops on Thursday December 12, 2024 @05:29PM (#42404091)
Note: Child processes can't change the working directory of the parent. An external command (that is, not a shell builtin, shell function, or externally loaded module) cannot change the working directory, because they're launched as child processes.
Re:"Rules" that terminal programs follow by saghm on Thursday December 12, 2024 @08:29PM (#42405186)
Good point. I'm not sure why I was thinking that it was possible to do via some other command invoking `cd` or something, but you're right that the only examples I can think of are all using other builtins (e.g. invoking `source` to have a script change the current state).
Re:"Rules" that terminal programs follow by d3VwsX on Friday December 13, 2024 @09:25AM (#42408662)
There is a workaround I saw used by wcd, a tool for changing directories. To install it you have to add a wrapper function in your shell that executes the actual wcd binary, and after possibly interacting with the user to figure out what directory to change to the executable will print out the destination, and then the wrapper function will make the call to cd, affecting the shell it runs in.

https://wcd.sourceforge.io/

Re:"Rules" that terminal programs follow by model-15-DAV on Tuesday December 17, 2024 @11:59PM (#42448226)
True, I meant the shell, as `cd` is a shell builtin. However, `git-checkout` does implement this behavior. `git checkout -` will checkout the previously checked out branch.