Copy working directory from one terminator screen to another - terminator

How can one copy with keyboard shortcuts the working directory of one terminator screen to another ?
For example, I have two split windows (thanks to Ctrl+Shift+E). One of them has its working directory (wd) set to ~ and the other has its wd set to ~/work/old/project/foo/bidule/version-2.6.7-a-beta/empty/test/latest. I would like to change the wd of the first to wd of the second.
First method, type cd ~/work/old/… on the first split window. This works, but its a difficult task because the directory name is long and hard to type.
Second method, type cd on the first split window, then copy and paste the path from the prompt of the second terminal (or from pwd if the prompt does not contain the complete path). This works, but we need to copy and paste a text from a terminal with the mouse, which is a difficult task for someone who has always his hands on the keyboard. :)
Is there a way with shortcuts to do the same stuff ?

(I'm running BASH on Debian Jessie derived Bunsen Linux; terminator 0.97)
My default terminator defines Ctrl+Tab as 'Focus the next terminal' and
seems to switch the cursor back and forth between split terminals.
You might have to also install xdotool:
$ sudo apt-get install xdotool
Then use the X selection to save the current working directory & paste it over to the other terminal.
echo $PWD | xsel -i; xdotool key Ctrl+Tab; xdotool type 'cd $(xsel
-o)'; xdotool key Return

I have found a method that is based on a copy/paste, but that is available on keyboard.
Record two aliases in your .bashrc (or into your shell configuration file, I do not know zsh, csh…):
alias cywd='pwd | xclip -i' # CopY WD
alias pswd='cd "xclip -o"' # PaSte WD
Then, you are able to copy the current working from a terminal by typing cywd and go to this folder by typing pswd into another terminal.
This solution is not perfect, mainly because is not easily available if a program is launched on the terminal you want to copy the WD from (for example vim or emacs -nw). However, it works. Waiting for better…

Related

Restrict zsh tab completion behavior

My zsh has some completion features I don't understand and can't find where to change. I have two issues where I suspect they have a similar "fix" for my problem. I initialize the zsh completion system with
autoload -Uz compinit
compinit
to get advanced completion features, but I also get the following problems that I don't have without compinit.
First: I happen to have a directory called mydir in my home directory and unfortunately, there is also a user called mydir. When I want to change into my directory and then use tab completion, i.e.
cd mydir/<TAB>
I get the content directories of ~myusername/mydir/ along with all directories available for ~mydir/. I already tried to put
zstyle ':completion:*' users myusername
in my .zlogin file, but it does only change the completion of the username itself and not subsequent directories. Is there some similar switch to turn off completion of other users' home directories? Alternatively, it would already be good if the current directory completion would appear first in the completion menu.
Second: I wrote a script called setup-file-with-a-long-name.sh that resides in my home directory. When I want to execute it via
source setup-file-with-a-long-name.sh
I start with the first few characters, I press <TAB> and I get a list of lots of executable files that are probably somewhere on my $PATH installed by the system, but I don't care about all those files, I just want my file (which is the only match in the current directory) to be displayed either first in the menu and accessible via <TAB> <TAB> or better yet, be accepted after the first <TAB>. (If I select any of them, they don't work anyway because source needs the absolute path, not the filename. Therefore this is a behavior I don't understand and can't see how this is useful as a default for anybody.)
Possible workarounds:
1. Write ~/ explicitly - this is what I want to avoid, because I have to ssh into a new shell pretty often and want to start navigating without thinking about whether I am in $HOME or not.
2. Don't use compinit - well, I like the context-aware completion in principle, I just want to adapt it to my needs.
The following works in bash,
man source -
source filename [arguments]
Read and execute commands from filename in the current shell environment and return the exit status of the last command executed from filename. If filename does not contain a slash, file
names in PATH are used to find the directory containing filename. The file searched for in PATH need not be executable. When bash is not in posix mode, the current directory is searched if
no file is found in PATH. If the sourcepath option to the shopt builtin command is turned off, the PATH is not searched.
to disable the flag instructions are a little above the description of sourcepath
shopt [-pqsu] [-o] [optname ...]
Toggle the values of variables controlling optional shell behavior. With no options, or with the -p option, a list of all settable options is displayed, with an indication of
whether or not each is set. The -p option causes output to be displayed in a form that may be reused as input. Other options have the following meanings:
-s Enable (set) each optname.
-u Disable (unset) each optname.
-q Suppresses normal output (quiet mode); the return status indicates whether the optname is set or unset. If multiple optname arguments are given with -q, the return
status is zero if all optnames are enabled; non-zero otherwise.
-o Restricts the values of optname to be those defined for the -o option to the set builtin.
...
sourcepath
If set, the source (.) builtin uses the value of PATH to find the directory containing the file supplied as an argument. This option is enabled by default.
so executing the following should remove path from your tab completion...
shopt -u sourcepath

Accurev binaries and recursive keep

My problem is in two parts:
My team and I are using an Test Design Studio to write .vbs files in a Accurev Workspace. The problem is that Accurev recognize them as binaries instead text/ptext files... which causes problems when merging. Is there a setting in Accurev I can change to force it to recognize .vbs files as text/ptext?
All those binaries that are already in the stream, I need solution to convert them all into text/ptext. I've given up on the Client UI, because it means I'd have to go in the Workspace explorer and go through every single folder, one by one, and keep those binaries. Then I thought of the commands. I tried
2.1. accurev keep -c "keep ptext" -n -E ptext -R target_folder
2.2. accurev keep -c "keep ptext" -n -E ptext -R .
2.3. But I get a No Element Selected. That's because the "-n" flag is required for recursive, but it means it'll ignore non-modified files... and most of my files are backed and not modified... otherwise I can't even select the directory for keeping (I'll report "can't keep a directory"). I could create a file-list, but it would take as long as manually keeping all the files one by one. I also tried if I could work directly in the stream (since it has another empty stream above, it lists all it's files as outgoing), but I do not have the keep option in the stream. Is there an easy way to convert all files in stream/workspace as text/ptext?
Yes, you will need to enable a pre-create-trigger using the elem_type.pl script found in "accurev install dir/examples" on your server. Inside the elem_type file, you will see the directions for setting this trigger.
Yes, run the following command to generate a list of all the files in your workspace.
"accurev stat -a -ffl > list.txt"
Then run the this command to convert the files to ptext:
"accurev keep -c "ptext conversion" -E ptext -l list.txt"
Then you can promote those files.
Check the files with a hex editor to see if there are any non-ASCII characters.
If there's binary content in the file AccuRev will see those files as binary.
Overwrite the keep as jstanley suggested to change the type.
On the add use "accurev add -E ptext -c "your favorite comment" file.vbs

Filter command history by folder they were executed in?

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.

How do I get vim's :sh command to source my bashrc?

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.

Unix: Getting Export PATH to "Stick"

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.

Resources