<div dir="ltr"><div>I've tinkered with Bash prompts for a lot of years.  That's where this problem originates, but it can be considered just as a thought experiment if you prefer.</div><div><br></div><div>We have the directory we're in, for example:</div><div><br></div><div>    /Users/gorr/.bashprompt/really/deep/directory/structure/even/deeper</div><div><br></div><div>(I keep my prompts in ~/.bashprompt/ , and a very long directory name is often a cause of breakage, so I keep one around to break them ...)</div><div><br></div><div>I want to shorten the directory name to just the first letters:<br></div><div><br></div><div>    export newPWD=$(echo ${PWD} | sed -e "s@${HOME}@~@" -e 's@\(/.\)[^/]*@\1@g')</div><div>    echo $newPWD</div><div>    ~/./r/d/d/s/e/d</div><div><br></div><div>This does '~' replacement for $HOME and then substitutes the first letter of each directory for the full directory name.</div><div><br></div><div>Here's the question: if the first letter of the directory name is a dot '.', can sed then capture one character more so that the output would become:</div><div><br></div><div>    ~/.b/r/d/d/s/e/d</div><div><br></div><div>I think this would be pretty easy with Bash and a loop, but that's a lot of processing so I'd rather not go down that road.  I suspect sed is capable of this, but I haven't delved deeply enough into the tool to even know where to start.  This may in fact be a regex problem more than a sed problem - either way I'm kind of stumped.  I'm open to simpler implementations using other (standard system) tools as well.<br> </div><div><br>-- <br><div dir="ltr" class="gmail_signature" data-smartmail="gmail_signature">Giles<br><a href="https://www.gilesorr.com/" target="_blank">https://www.gilesorr.com/</a><br><a href="mailto:gilesorr@gmail.com" target="_blank">gilesorr@gmail.com</a></div></div></div>