Paste: home-path

Author: tgunr
Mode: factor
Date: Thu, 8 Dec 2011 20:15:48
Plain Text |
: home-path ( path -- newpath )
    ! after ~ is stripped, is there a username in front?
    [ "/" head? ] keep swap
    ! no, add in our home path
    [ home prepend-path ]
    ! yes, find the user home path
    [ path-components [ first user-passwd ] keep
      over
      ! found the user
      [ 
        ! strip name from seq
        0 swap remove-nth
        ! get user dir and prefix
        swap dir>> prefix
        ! rebuild path
        components-to-path
      ] [
          components-to-path
      ] if
    ] if
    ;

####

Asset: home-path

The input quotations to “if” don't match their expected effects
Input                                                      Expected       Got
[ 0 swap remove-nth swap dir>> prefix components-to-path ] ( ..a -- ..b ) ( x -- x )
[ components-to-path ]                                     ( ..a -- ..b ) ( x -- x x )
:errors - show 1 compiler errors

New Annotation

Summary:
Author:
Mode:
Body: