Change directory w/out changing screen line

Dec 7, 2009
221
2
Left Coast, USA
This falls into the realm of complete frivolity, but oh well. : ) For whatever reason -- the origin of this neurosis is lost in the mists of time -- I like to change directories and stay on the starting screen line. So after puzzling over how to do it for quite a while -- an alias, which I call "SameLine":

pushd %1 %+ screen -1 0 %+ drawhline %_row 0 80 0 %_bg on %_bg %+ screen -1 0

Then for switching to C:\batch, for example, another alias ("b"):

b=SameLine c:\batch

Does what I want unless the cursor is on the last screen line when the command is given.

I'm sure that a few years of therapy would cure me of this same-line-on-screen obsession, but once again: oh well.
: )
 
May 20, 2008
3,520
3
Elkridge, MD, USA
First, pushd is not the same as cd/d - it's really useful on the very rare occasion you want to go back into directories in reverse order of their last use. In fact I found myself often cycling through 3 or occasionally 4 directories.

You can easily wrap the CDD command into an alias which uses X3.64 escape sequences which work regardless of screen width to keep the cursor on the same line as before...
 
Dec 7, 2009
221
2
Left Coast, USA
I could use either pushd or cd /d, but I use "popd" often enough that pushd is useful. As for the X3.64 escape sequences -- do you have an example in mind?
 
May 20, 2008
9,184
60
Syracuse, NY, USA
Try this one.
Code:
alias sl `echos ^e[%_row;1H^e[K^e[1A & pushd %1`
It should change directories without changing lines EXCEPT when on line 0.

Note that <ESC>[K (not erasing the character at the cursor) but that should be OK since a new prompt should replace the old (almost erased) one.