Code Monkey home page Code Monkey logo

Comments (9)

KiteAB avatar KiteAB commented on September 25, 2024 1

@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.

KiteAB avatar KiteAB commented on September 25, 2024 1

I am surprised that you can give the final answer, thank you very much!

from magicmace.

KiteAB avatar KiteAB commented on September 25, 2024

Like from this: ~/Documents/GitHub
To this: ~/D/GitHub
And apply it to my gitster theme

from magicmace.

ericbn avatar ericbn commented on September 25, 2024

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:

  1. /${current_dir:t}: keep the tail directory (last directory in the path)
  2. ${(@s:/:)current_dir:h}: split the remaining directories into an array
  3. ${(@j:/:M)...#?}: join the first letter of the array elements
  4. ${...%/}: 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.

KiteAB avatar KiteAB commented on September 25, 2024

It's working! But there are still some small problems:
In git repositories, It's look's not nice.

from magicmace.

KiteAB avatar KiteAB commented on September 25, 2024

After short working directory:
Before short working directory:

from magicmace.

KiteAB avatar KiteAB commented on September 25, 2024

Pleasse remember me @ericbn

from magicmace.

ericbn avatar ericbn commented on September 25, 2024

@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.

ericbn avatar ericbn commented on September 25, 2024

@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 photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.