this post was submitted on 27 Jun 2023
42 points (95.7% liked)
Linux
48721 readers
2343 users here now
From Wikipedia, the free encyclopedia
Linux is a family of open source Unix-like operating systems based on the Linux kernel, an operating system kernel first released on September 17, 1991 by Linus Torvalds. Linux is typically packaged in a Linux distribution (or distro for short).
Distributions include the Linux kernel and supporting system software and libraries, many of which are provided by the GNU Project. Many Linux distributions use the word "Linux" in their name, but the Free Software Foundation uses the name GNU/Linux to emphasize the importance of GNU software, causing some controversy.
Rules
- Posts must be relevant to operating systems running the Linux kernel. GNU/Linux or otherwise.
- No misinformation
- No NSFW content
- No hate speech, bigotry, etc
Related Communities
Community icon by Alpár-Etele Méder, licensed under CC BY 3.0
founded 5 years ago
MODERATORS
you are viewing a single comment's thread
view the rest of the comments
view the rest of the comments
At my old job I wanted to use zsh, but all the build and test scripts only worked in bash or csh, because they would depend on you sourcing other scripts setting up the correct environment for the project you were currently working in. The scripts were also quite slow, and sometimes one script would depend on changes to the environment done by a different script, so it wasn't feasible to simply launch a new bash shell each time I wanted to run something.
So my hack was to write a zsh function that would spawn a bash process in the background, source the environment depending on your current folder, and then wait for commands. The zsh function then piped the command line to run to bash, which in turn piped any output from the command back to the foreground shell. On the next invocation it would reuse the already running bash process, and if it detected that you had changed dir to a different project it printed a warning that you probably wanted to re-start the bash shell (which was done with another zsh function).
E.g.
b tb7 build
would run "tb7 build" in the bash background process while to the user appearing as if had been run normally in a foreground shell. Thenb tb7 test
would run "tb7 test" in the same bash process as the previous command.Since I worked a lot in terminals connected to remote servers, I also wrote zsh functions for copying the current directory, and another for cd-ing to whatever is in the copy-paste buffer. If it was only locally I would press ctrl-shift-t to open a new terminal at the same location, but it doesn't work if you first have to open another ssh connection. Later I started using tmux and these functions became less useful.
The third "hack" I made was to easier resume work in terminals where the ssh connection had timed out. My zsh prompt prints a shortened version of the current directory, e.g. "/storage/cnffhein/proj/monkeys/somemodule/dir/anothersubmodule/cloned/src" prints as "/s/c/p/m/s/d/a/c/src >>>" so my function did a depth first search of the file system to find a path that matched the abbreviation and cd:d there. Since everybody had the same prefix to their username and had the same projects checked out I made it search any dir matching my username first. E.g.
ccd /s/c/p/m/s/d/a/c/src
would find and cd to /storage/cnffhein/proj/monkeys/somemodule/dir/anothersubmodule/cloned/src