Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>How about a Python script? This shortens the longest directory names first, one character at a time until it meets its length goal or cannot get the path any shorter. It does not shorten the last directory in the path.</p> <p>(I started writing this in plain shell script but man, bash stinks at string manipulation.)</p> <pre><code>#!/usr/bin/env python import sys try: path = sys.argv[1] length = int(sys.argv[2]) except: print &gt;&gt;sys.stderr, "Usage: $0 &lt;path&gt; &lt;length&gt;" sys.exit(1) while len(path) &gt; length: dirs = path.split("/"); # Find the longest directory in the path. max_index = -1 max_length = 3 for i in range(len(dirs) - 1): if len(dirs[i]) &gt; max_length: max_index = i max_length = len(dirs[i]) # Shorten it by one character. if max_index &gt;= 0: dirs[max_index] = dirs[max_index][:max_length-3] + ".." path = "/".join(dirs) # Didn't find anything to shorten. This is as good as it gets. else: break print path </code></pre> <p>Example output:</p> <pre><code>$ echo $DIR /this/is/the/path/to/a/really/long/directory/i/would/like/shortened $ ./shorten.py $DIR 70 /this/is/the/path/to/a/really/long/directory/i/would/like/shortened $ ./shorten.py $DIR 65 /this/is/the/path/to/a/really/long/direc../i/would/like/shortened $ ./shorten.py $DIR 60 /this/is/the/path/to/a/re../long/di../i/would/like/shortened $ ./shorten.py $DIR 55 /t../is/the/p../to/a/r../l../di../i/wo../like/shortened $ ./shorten.py $DIR 50 /t../is/the/p../to/a/r../l../d../i/w../l../shortened </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload