Opening new tab and running scripts in both tabs - bash

I'm trying to write (what I thought would be) a simple zsh script to set up my development environment. The problem I'm running into is that once I get to part of my process, that tab in the shell is devoted only to the last process when I need it to continue running other commands.
More explicitly, I need to run:
lein ring server-headless
then open a new tab, and run
cd ../
cd my_directory/
nodemon
I'm sure this has a simple solution/I should have been a better-Googler, I'm just new to this and didn't know how to word my problem.

Instead of trying this with bash/zsh/etc. I would recommend using Tmux instead :)
Take a look at Tmuxinator for this stuff: https://github.com/aziz/tmuxinator
If you don't want to use tmuxinator, with a few lines of shell code you can still make tmux do this stuff.

Related

How to quickly show program help in pager

I often find myself appending --help|less to commands that I am crafting a command in a shell to explore the CLI of the program I am using. What ways are there to accomplish the same thing with fewer key-presses?
For instance, if I wanted to use the new way of switching branches (I don't, I'm stuck in my ways happily doing git checkout -b other_branch) then my history (and thought process) could look like
git change other_branch # Guess what the command should be
git --help|less # Backtrack to where I am confident I know the command and ask for help
git switch --help|less # Gradually build up the command from there
git switch other_branch
For context:
I typically want the pager either to be able to search or because I am working in tmux and activating scrolling takes a few additional, and awkward, key-presses.
I typically use zsh on Ubuntu or Debian.
I typically use arrow up to iterate on my previous command.
Add the following to your .zshrc file:
# Alt-H: Open `man` page of current command.
unalias run-help
autoload -Uz run-help{,-{git,ip,openssl,p4,sudo,svk,svn}}
Then restart your shell.
Now, whenever you're in the middle of typing a command, you can press AltH (^[h) to immediately open the man page for that command. Then, after you quit your pager, Zsh will will automatically restore your command line, so you can finish typing.

Run msys2 shell in VSCode terminal

I am working with (a customized install of) msys2, and I would like to make it run in the VSCode integrated terminal. However, it doesen't seem to want to run there. Unlike normal msys, it has msys2_shell.bat & msys2_shell.cmd. It seems to always open up a separate shell window, but I don't want this to always happen, I would like to keep it integrated so I can use shortcuts and such. I already tried the -no-start option. Any suggestions?
Thanks!
msys2_shell.cmd -no-start -defterm could work. Other than that, you can invoke Bash directly if you remember to set MSYSTEM and invoke a login shell: C:\msys64\usr\bin\env MSYSTEM=MSYS /usr/bin/bash -li
For more details, see https://www.msys2.org/wiki/Launchers/.

Changing login path without modifying $HOME

When I start a terminal session and my shell starts I'd like it to log me in a specific directory instead of $HOME.
For example, I've noticed I often start a new shell session and move to /tmp just to clone a git repository or do some quick and temporary stuff, and I would like to be logged directly in a directory of mine like /sandbox or something at my shell startup rather than my $HOME directory.
Any of you aware of a way to achieve this without modifying my user's home directory nor adding a dumb cd /sandbox in my .zshrc ?
Thank you very much!
My preferred solution for issues like this is to use a bunch of wrapper scripts that set the desired environment properties and then exec an interactive shell, passing through any command line arguments:
#!/bin/sh
# sandbox-sh
cd /sandbox
exec bash "$#"
Even better, you can launch GNU screen or tmux instead of a single shell - any new windows you create will share the same properties as the first one. Alternatively, you may also launch a tabbed terminal emulator - any new tabs will also share the environment defined in the wrapper script.

In Bash, how can I tell if I am currently in a terminal

I want to create my own personal logfile that logs not only when I log in and out, but also when I lock/unlock my screen. Kindof like /var/log/wtmp on steroids.
To do this, I decided to run a script when I log into Ubuntu that runs in the background until I quit. My plan to do this is to add the script to .bashrc, using ./startlogging.sh & and in the script I will use trap to catch signals. That's great, except .bashrc gets run every time I open a new terminal, which is not what I want for the logger.
Is there a way to tell in Bash that the current login is a gnome login? Alternatively, is there some sort of .gnomerc I can use to run my script?
Edit: Here is my script:
Edit 2: Removed the script, since it's not related to the question. I will repost my other question, rather than repurpose this one.
Are you looking for a way to detect what type of terminal it is?
Try:
echo $TERM
From Wikipedia:
TERM (Unix-like) - specifies the type of computer terminal or terminal
emulator being used (e.g., vt100 or dumb).
See also: List of Terminal Emulators
for bash use : ~/.bash_logout
that will get executed when you logout, which sounds like what you are trying to do.
Well, for just bash, what you want are .bash_login/.bash_logout in your home directory (rather than .bashrc) These are run whenever a LOGIN shell starts/finishes, which happens any time you log in to a shell (on a tty or console, or via ssh or other network login). These are NOT run for bash processes created to run in terminal windows that you create (as those are not login shells) so won't get run any time you open a new terminal.
The problem is that if you log in with some mechanism that does not involve a terminal (such as gdm running on the console to start a gnome or kde or unity session), then there's no login shell so .bash_login/logout never get run. For that case, the easiest is probably to put something in your .xsessionrc, which will get run every time you start an X session (which happens for any of those GUI environments, regardless of which one you run). Unfortunately, there's no standard script that runs when an X session finishes.

Start script on login

I have written a ruby daemon and I would like for it to run when I log in. It is normally run by going to the command line and calling ruby my_ruby_script.rb. How can I start my daemon on login? (Running 10.6 Snow Leopard).
There's an option to add applications etc that need to start at login, you could try writing a shell script or an apple script thing that launches terminal and runs ruby my_ruby_script.rb, or possibly even just add my_ruby_script.rb to this list after adding a #!/bin/env ruby line to the top of that file. http://support.apple.com/kb/HT2602?viewlocale=en_US gives precise instructions as to how to add an application to be started at login.
If you need to use AppleScript to actually start a terminal application (I believe this is not the case, but I am not in front of my mac now and hence can't test), just create an applescript file with something like
do shell script "ruby <path>/my_ruby_script.rb"
Hope this helps
As Panda said, add:
#!/bin/env ruby
to the begining of the file, and then you could add a reference to your file inside ~/.bashrc or ~/.profile or even /etc/profile , depending on your needs.
Check this out: https://stackoverflow.com/questions/3484429/profile-and-bashrc-doesnt-work-on-my-mac/3484472#3484472

Resources