Comments (9)
@KiteAB, it's been only 14 hours since your reply, and now you sound demanding. It's not fair to address me or any other person who puts their free time in trying to build a great piece of software, in this manner.
Oh, sorry. Sorry to bother you, my problem has been basically solved, thank you
from magicmace.
I am surprised that you can give the final answer, thank you very much!
from magicmace.
Like from this: ~/Documents/GitHub
To this: ~/D/GitHub
And apply it to my gitster theme
from magicmace.
Hi @KiteAB, this is the code that shortens the pwd:
local current_dir=${PWD/#${HOME}/~}"
if [[ ${current_dir} != '~' ]]; then
current_dir="${${(@j:/:M)${(@s:/:)current_dir:h}#?}%/}/${current_dir:t}"
fi
The longest line is doing most of the work:
/${current_dir:t}
: keep the tail directory (last directory in the path)${(@s:/:)current_dir:h}
: split the remaining directories into an array${(@j:/:M)
...#?}
: join the first letter of the array elements${
...%/}
: remove extra slash in case we're in the root directory
You can apply the same code to your custom prompt. If you want to use that with gitster, it will look like:
local git_root current_dir
if git_root=$(command git rev-parse --show-toplevel 2>/dev/null); then
current_dir="${PWD#${git_root:h}/}"
else
current_dir=${PWD/#${HOME}/~}"
fi
if [[ ${current_dir} != '~' ]]; then
current_dir="${${(@j:/:M)${(@s:/:)current_dir:h}#?}%/}/${current_dir:t}"
fi
print -n "%F{white}${current_dir}"
from magicmace.
It's working! But there are still some small problems:
In git repositories, It's look's not nice.
from magicmace.
After short working directory:
Before short working directory:
from magicmace.
Pleasse remember me @ericbn
from magicmace.
@KiteAB, it's been only 14 hours since your reply, and now you sound demanding. It's not fair to address me or any other person who puts their free time in trying to build a great piece of software, in this manner.
from magicmace.
@KiteAB, you might want to use this with gitster. It will keep the git root directory unshortened too, which I think goes well with the spirit of this prompt:
local git_root current_dir
if git_root=$(command git rev-parse --show-toplevel 2>/dev/null); then
current_dir="${PWD#${git_root:h}/}"
else
current_dir=${(%):-%~}
fi
local -r dirs=("${(@s:/:)current_dir}")
if (( ${#dirs} > 2 )); then
current_dir="${dirs[1]}/${(@j:/:M)dirs[2,-2]#?}/${dirs[-1]}"
fi
print -n "%F{white}${current_dir}"
from magicmace.
Related Issues (3)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from magicmace.