It's very common to have a terminal window opened in a specific folder, and then you realize that you need to do something else in that same folder, then you open a new terminal window and have to navigate to the folder that you were in the previous window, it's happens a lot and it's annoying.
There's a quick and easy way to solve this problem that works in any platform, terminal emulator etc..
Just create a script called pwdc place the following code
#!/usr/bin/bash
pwd | xclip -selection clipboard
What this script does is to copy your current directory to your clipboard
pwd means (print working directory), that's why the name of the script is pwdc, the c stands for copy, but of course, you can name the script whatever you want, after creating the script you need to make it executable
chmod +x ./pwdc
and you also need to install xclip if you don't already have, after that you need to move the script to your path, so you can call it anywhere, and that's it, now you can easily copy you current directory open a new terminal window and navigate to it
Top comments (2)
on macos:
use pbcopy and pbpaste!
on node:
I use clipboardy package, it works well. :D
linux tip:
use a clipboard history widget on desktop or something similar! it really helps to re-copy something you copied a while ago.
On the same topic I would like to add, sometimes we run a command and we want to copy the command we just ran onto clipboard. For that I have a solution. In the same way create another bash file and put this piece of code.
Make it executable in the same way as shown above. If you want to access the file anywhere from the terminal just put it in
/bin/
directory.