Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

No commit message

  • Loading branch information...
commit 62d1d5764c598b640b62fa35f119049775aed7e7 0 parents
rupa authored February 16, 2009

Showing 1 changed file with 44 additions and 0 deletions. Show diff stats Hide diff stats

  1. 44  j.sh
44  j.sh
... ...
@@ -0,0 +1,44 @@
  1
+# jump-list of directories
  2
+# source into .bashrc
  3
+# use: j [mask1] ... [maskn]
  4
+j() {
  5
+ jfile=$HOME/.j
  6
+ [ "$1" = "--add" ] && {
  7
+  shift
  8
+  awk -v d="$*" -v mx=1000 -F"|" '
  9
+   $2 >= 1 { 
  10
+    if( $1 == d ) { l[$1] = $2 + 1; x = 1 } else l[$1] = $2
  11
+    y += $2
  12
+   }
  13
+   END {
  14
+    if( !x ) l[d] = 1
  15
+    if( y > mx ) {
  16
+     for( i in l ) print i "|" l[i]*(0.9*mx/y)
  17
+    } else for( i in l ) print i "|" l[i]
  18
+   }
  19
+  ' $jfile 2>/dev/null > $jfile.tmp
  20
+  mv $jfile.tmp $jfile
  21
+  return
  22
+ }
  23
+ local IFS='
  24
+'
  25
+ set -- $(awk -v r="$*" -F"|" '
  26
+  BEGIN { split(r,a," ") }
  27
+  { for( o in a ) if( $1 !~ a[o] ) $1 = ""; if( $1 ) print $2 "\t" $1 }
  28
+ ' $jfile | sort -nr | cut --complement -f 1)
  29
+ if [ $# -eq 0 ]; then
  30
+  return
  31
+ elif [ $# -eq 1 ]; then
  32
+  cd "$1"
  33
+ else
  34
+  for x in "$@"; do
  35
+   echo $x
  36
+  done | nl -n ln
  37
+  echo -n "Number: "
  38
+  read C
  39
+  [ "$C" = "0" -o -z "$C" ] && return
  40
+  eval D="\${$C}" 2>/dev/null
  41
+  [ "$D" ] && cd "$D"
  42
+ fi
  43
+}
  44
+PROMPT_COMMAND='j --add "$(pwd -P)";'"$PROMPT_COMMAND"

0 notes on commit 62d1d57

Please sign in to comment.
Something went wrong with that request. Please try again.