I have some commands in mind that I don't want to create keybinds for and would prefer to use command mode for them. For example, I want something like:
<C-a>:restart-guard
That I can have run a script to run some commands in my guard window
Is this possible?
You can't define user defined commands directly
But you can always call a tmux script with so (shortest alias of source-file) or a program with ru (shortest alias of run-shell)
For so, you need to give the path to the command or to have the tmux server to start in the folder where your custom commands are
Here is a simple example, you put your restart-guard script in ~/.tmux/commands
you start tmux using a scipt :
#!/bin/bash
cd ~/.tmux/commands
tmux
then inside tmux, do
<C-a>:so restart-guard
I am currently looking for a way to have the directory where you started tmux and not the ~/.tmux/commands directory when starting
That is unfortunately not possible with tmux at this moment.
Related
I have an issue where my Control-M job is not able to execute anything on the unix box.
after investigation found out that .profile file in the unix server is the culprit.
content of the .profile file is
exec bash
I tried renaming the file and run the job in UAt and it did work where as I am not sure whats the implication of not having this file.
Can some one pls help me with explaining
what would be the overall impact if I rename the .profile file
how the content of .profile file being used in the server
I don't know what this "Control-M" thing is, but you should be able to safely remove that one-line .profile from your account with no problem. All it does is replace whatever command shell is assigned by default to your account with the command shell called bash. If you don't care if you use the default shell or bash, and especially if you are having problems with that .profile file, then just remove it.
If you really want to use bash then you might try changing your default shell with the chsh command. That may also cause problems for this "Control-M" thing, so you'll want to read the chsh manual page to be sure you know how to determine what your current shell is and how to change back to the original value if there are any problems.
I know shell history doesn't keep track of the folder the commands were executed in but I think it would be really useful to be able to output the history for a particular folder by using a flag like history --local for example.
I often jump from project to project which use very similar commands but have different destination host for ssh or environment variable...
Is there any way to achieve that –preferably using zsh?
In bash, you can set PROMPT_COMMAND to something like the following:
PROMPT_COMMAND='history | tail -n1 >> .$USER.history'
It will save each command to a file in the current directory.
For an alternative approach (replacing cd with a command that changes where history is saved), see http://www.compbiome.com/2010/07/bash-per-directory-bash-history.html.
Zsh has a feature that lets it prompt for corrections to files in the current directory. Eg, if I say cd bar when I mean to say cd baz, then zsh will say: zsh: correct 'bar' to 'baz' [nyae]?
Normally, this works fine. However, sudo seems to mess things up. Specifically, suppose I want to version control my apache2 directory with git. I would type something like sudo git add . This is the correct command to run. However, zsh would prompt me with zsh: correct 'git' to '.git' [nyae]? as if it didn't know that git was a command, so it thought I was trying to refer to the .git folder.
Why is this happening? How can I get it to stop prompting me in those situations?
Thanks!
EDIT: It seems like zsh, by default, will consider all arguments to a command to be files or directories. However, I know that there is some functionality to extend this. For instance, if I type git sttab, then zsh will complete it to stash, status, or stripspace (with documentation on each of those). I would, ideally, like zsh to keep providing tips like these even with something like sudo (so, I would rather not do a nocorrect). How do I customize that functionality in zsh?
Either use nocorrect before the command itself, or define an alias
alias sudo="nocorrect sudo"
Whenever I start a shell in vim using :sh, it doesn't source my ~/.bashrc file. How can I get it to do this automatically?
See :help 'shell'. You can set this string to include -l or --login, which will source your .bashrc file. So, you might have a line like this in your .vimrc:
set shell=bash\ --login
Note that this will alter everything that invokes the shell, including :!. This shouldn't be much of a problem, but you should be aware of it.
The value of this command can also be changed by setting the $SHELL environment variable.
If it doesn't source your .bashrc file, it may still source your .bash_profile file. I usually make one of them a symlink to the other. If your .bashrc performs some particularly odd one-time operations, you may have to edit it to only perform those operations with a login shell, but I've never had problems with it.
~/.vimrc
cmap sh<CR> !bash --login<CR>
If you quickly enter "sh<Enter>" in command-line, you can start bash with sourcing ~/.bashrc. So dirty.
When setting the export path in Unix, example:
export PATH=$PATH: $EC2_HOME/bin
If I quit terminal and open it back up to continue working, I have to go through all the steps again, setting up the paths each time.
I'm wondering how I can set the path and have it "stick" so my system knows where to find everything the next time I open terminal without having to do it all over again.
Thanks!
Open ~/.bashrc. This file is loaded every time you start up a new shell (if you're using Bash, which most people are). If you're using a different shell, the file may have a different name, like ~/.shrc.
Add the line you need to the bottom of the file:
export PATH=$PATH:$EC2_HOME/bi
Other info rolled up from elsewhere in the thread:
There are multiple places to put this, depending on your shell and your needs. All of these files are in your home directory:
For Bash:
.bashrc (executed when you shart a shell)
OR
.bash_profile (executed when you log in)
For csh and tcsh:
.cshrc
For sh and ksh:
.profile
Add it to your .cshrc file (for csh and tcsh), .profile file (for sh and ksh), or .bash_profile file (for bash)
You need to find your profile file and put that line in there. Suppose you use bash, the profile files are .bashrc and .bash_profile, found in ~. These files will vary depending on which shell you use.
You have to put those commands into one of the "autostart" files of your shell.
For bash this would be .bashrc in your homedirectory (create it if necessary)
add it to your .bashrc or another .bash startup file.
... and for ksh edit .profile.