### Copyright (C) 1995-1997 Jesper K. Pedersen
### This program is free software; you can redistribute it and/or modify
### it under the terms of the GNU General Public License as published by
### the Free Software Foundation; either version 2 of the License, or
### (at your option) any later version.
###
### This program is distributed in the hope that it will be useful,
### but WITHOUT ANY WARRANTY; without even the implied warranty of
### MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
### GNU General Public License for more details.
###
### You should have received a copy of the GNU General Public License
### along with this program; if not, write to the Free Software
### Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.


proc path {} {
  # path
  global argv
  
  Desc "Here you configure two paths. The first one is your search path,"\
      "which is the path, where you can execute programs from. The second"\
      "is the cdpath, which is the directories you can cd to, without"\
      "being in its parent."
  
  ShortDesc "Configuration of path"

  ############################### Widgets ##############################
  Dir-Browser pathComponent -text path
  ExtEntry path \
      -entries frame_pathComponent\
      -text Search path -export 0
  Command readPath -setvalue {$widget configure -text "Load path from system"} \
      -invoke {
        if {[info exists env(PATH)]} {
          foreach elm [split $env(PATH) ":"] {
            AddTuple path
            set pathComponent $elm
            set com_pathComponent $elm
          }
        }
      }
  
  Line l1
  
  Dir-Browser cdPathComponent  -text path
  ExtEntry cdPath \
      -entries frame_cdPathComponent \
      -text "Directories \\\"cd\\\" should search for subdirs in"
  
  ################################ Help ################################
  Help pathComponent \
      "This is a single path, in which a binary shall be found. (More"\
      "help on header)"
  Help path \
      "When you wish to start a program, the these directories (called"\
      "the path) are searched for a program with execute permission.\n"\
      "Note: If you want to be able to run a program from your current"\
      "directory, you need to have \".\" in your path.\n If you change"\
      "the path from the prompt, remember to run the command"\
      "\"rehash\"!"
  Help cdPathComponent\
      "This is a path, you can cd to without being in its parent"\
      "directory (more help on the header)"
  Help cdPath \
      "Here you can set up a lot of directories, which you can cd to"\
      "without being in it's parent directory.\n if your current"\
      "working directory is eg. \"~/\" and you have \"/usr/local\" in"\
      "this variable, then you can type \"cd bin\" and go to"\
      "\"/usr/local/bin\", unless you have a \"bin\" directory as a"\
      "subdir of your current directory. In that case you would cd, to"\
      "that directory."

  ################################ Save ################################
  Save {
    ########## path ##########
    set dirs ""
    forevery path {
      if {$pathComponent != ""} { 
        append dirs "\t$pathComponent\\\n"
      }
    }
    if {$dirs != "" || $generateDefault} {
      print "set path = (\\\n$dirs)"
    }
    ########## cdpath ##########
    set dirs ""
    forevery cdPath {
      if {$cdPathComponent != ""} {
        append dirs "\t$cdPathComponent\\\n"
      }
    }
    if {$dirs != "" || $generateDefault} {
      print "set cdpath = (\\\n$dirs)"
    }
  }
}
