Skip to content

Instantly share code, notes, and snippets.

@longarm
Last active December 15, 2015 23:00
Show Gist options
  • Save longarm/5337397 to your computer and use it in GitHub Desktop.
Save longarm/5337397 to your computer and use it in GitHub Desktop.
In Perforce, user will have a request to jump between center and local client by soft link .s for example local client directory: /a/b/c/d/e/f ; center directory /a/b/c/.s/d/e/f
import os
currentPath=os.getcwd()
tail=''
while currentPath != '/':
aa=os.path.split(currentPath)
tail=os.path.join(aa[1], tail)
if os.path.lexists(os.path.join(aa[0],'.s')):
os.chdir(os.path.join(aa[0], '.s', tail))
break
currentPath=aa[0]
print os.getcwd()
#!/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
cd ..
end
#pwd
@delta4d
Copy link

delta4d commented Apr 8, 2013

wanna go back

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