Skip to content

Instantly share code, notes, and snippets.

@delta4d
Last active December 15, 2015 22:59
Show Gist options
  • Save delta4d/5336680 to your computer and use it in GitHub Desktop.
Save delta4d/5336680 to your computer and use it in GitHub Desktop.
#!/usr/bin/env tcsh
# description: change dir based on .s
# with any arguments to go back
# TODO there is some problems with heredoc
set pd=
set cc=
while ( 0 == 0 )
if ( -d .s ) break
set cc=`pwd`
set cc=`echo $cc | sed -e 's/.*\/\(.*\)/\1/g'`
if ( $# == 0 || $cc != ".s" ) set pd=$cc/$pd
#echo $pd
cd ..
end
if ( $# == 0 ) set pd=.s/$pd
#echo $pd
cd $pd
pwd
#!/usr/bin/env sh
pd=
while true; do
[[ -d .s ]] && break
cc=`pwd`
pd=${cc##*/}/$pd
# echo $pd
cd ..
done
pd=.s/$pd
#echo $pd
cd $pd
pwd
@delta4d
Copy link
Author

delta4d commented Apr 9, 2013

#!/usr/bin/env tcsh

set pd=
set cc=

while ( 0 == 0 )
    if ( -d .s ) break
    set cc=`pwd`
    set cc=`echo $cc | sed -e 's/.*\/\(.*\)/\1/g'`
    set pd=$cc/$pd
    #echo $pd
    cd ..
end

set pd=.s/$pd
#echo $pd
cd $pd
pwd

@delta4d
Copy link
Author

delta4d commented Apr 9, 2013

#!/usr/bin/env tcsh
# description: change dir based on .s
# with any arguments to go back
# TODO there is some problems with heredoc

set pd=
set cc=

while ( 0 == 0 )
    if ( -d .s ) break
    set cc=`pwd`
    set cc=`echo $cc | sed -e 's/.*\/\(.*\)/\1/g'`
    if ( $# == 0  || $cc != ".s" ) set pd=$cc/$pd
    #echo $pd
    cd ..
end

if ( $# == 0 ) set pd=.s/$pd
echo $pd
cd $pd
pwd

@longarm
Copy link

longarm commented Apr 10, 2013

#!/usr/bin/env tcsh
# description: change dir based on .s
# with any arguments to go back
# TODO there is some problems with heredoc

set pd=
set cc=
set origin=$PWD

while ( 0 == 0 )
    if ( -d .s ) then  
        set pd=.s/$pd
        cd $pd
        break
    endif

    set cc=$PWD
    set cc=`echo $cc | sed -e 's/.*\/\(.*\)/\1/g'`
    if ( $cc == "") then
        cd $origin
        break
    endif
    if ( $cc != ".s" ) then
        set pd=$cc/$pd
    else 
        cd ..
        cd ./$pd
        break
    endif

#   echo $pd
    cd ..
end

pwd

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment