Commits

Martin Tournoij  committed 005bd1a

Update

  • Participants
  • Parent commits 4532687

Comments (0)

Files changed (4)

File home/dot.tcsh/aliases.tcsh

 # Update xterm title on directory change (special alias)
-if ($uname != win32 && -f ~/.tcsh/cwdcmd) then
-	alias cwdcmd source ~/.tcsh/cwdcmd
+if ( $uname != win32 && -f ~/.tcsh/cwdcmd.tcsh ) then
+	alias cwdcmd source ~/.tcsh/cwdcmd.tcsh
+else
+	unalias cwdcmd
 endif
 
 alias helpcommand man

File home/dot.tcsh/completions.tcsh

 	verify-pack merge-file verify-tag merge-index web--browse \
 	merge-octopus whatchanged merge-one-file write-tree merge-ours)/' \
 	'n@checkout@`git branch -a | sed -r "s|^[\* ]+(remotes/origin/)?||; /^HEAD/d" | sort -u`@' \
-	'n@branch@`git branch -a | sed -r "s|^[\* ]+(remotes/origin/)?||" /^HEAD/d | sort -u`@'
+	'n@branch@`git branch -a | sed -r "s|^[\* ]+(remotes/origin/)?||; /^HEAD/d" | sort -u`@'
 
 complete find 'n/-fstype/"(nfs 4.2)"/' 'n/-name/f/' \
 	'n/-type/(c b d f p l s)/' \
 		print0 printf not a and o or)/' \
 	'n/*/d/'
 
-# Only list make targets
-if ($uname == FreeBSD && `uname -r | cut -d. -f1` < 10) then
-	complete make 'n@*@`make -pn | sed -n -E "/^[#_.\/[:blank:]]+/d; /=/d; s/[[:blank:]]*:.*//gp;"`@'
-else
-	complete make 'n@*@`sh -c "make -dg1 -n 2>&1 | grep ,\ flags\ \[0-9\]\*,\ type\ \[0-9\]\* | cut -wf2 | tr -d , | sed /^\[^a-z\]/d | sort -u"`@'
+# pmake & GNU make
+if ( $uname == FreeBSD ) then
+	set backslash_quote
+	complete gmake 'n@*@`make -qp | awk -F: \'/^[a-zA-Z0-9][^$#\/\t=]*:([^=]|$)/ { split($1,A,/ /); for(i in A)print A[i] }\' | sort -u`@'
+	unset backslash_quote
+
+	if ( `uname -r | cut -d. -f1` < 10 ) then
+		complete make 'n@*@`make -pn | sed -n -E "/^[#_.\/[:blank:]]+/d; /=/d; s/[[:blank:]]*:.*//gp;"`@'
+	else
+		complete make 'n/*/`make -V .ALLTARGETS`/'
+	endif
+else if ( $uname == Linux ) then
+	set backslash_quote
+	complete make 'n@*@`make -qp | awk -F: \'/^[a-zA-Z0-9][^$#\/\t=]*:([^=]|$)/ { split($1,A,/ /); for(i in A)print A[i] }\' | sort -u`@'
+	unset backslash_quote
 endif
 
 complete dd 'c/if=/f/' 'c/of=/f/' \

File home/dot.tcsh/cwdcmd

-# vim:set syntax=tcsh
-
-echo -n "\033]2;tcsh: $cwd\007"
-
-unset printexitvalue
-
-# Only get the branch once, for the sake of efficiency
-if ( $?reporoot ) then
-	if ( "$cwd" =~ "$reporoot*" ) then
-		# TODO: Git specific
-		if ( $reporoot == `stat -c%Y "$reporoot"/.git/HEAD` ) then
-			goto end
-		endif
-	endif
-endif
-
-hg branch >& /dev/null
-if ( $? == 0 ) then
-	set repo = `hg branch`
-	set prompt = "[%~]($repo)%# "
-	set reporoot = `hg root`
-	goto end
-endif
-
-git rev-parse --abbrev-ref HEAD >& /dev/null
-if ( $? == 0 ) then
-	set repo = `git rev-parse --abbrev-ref HEAD`
-	set prompt = "[%~]($repo)%# "
-	set reporoot = `git rev-parse --show-toplevel`
-	set repochanged = `stat -c%Y "$reporoot"/.git/HEAD`
-	goto end
-endif 
-
-set prompt = "[%~]%# "
-unset reporoot
-unset repochanged
-
-
-end:
-	# TODO: Don't assume it was set
-	set printexitvalue

File home/dot.tcsh/cwdcmd.tcsh

+# vim:set syntax=tcsh
+
+# Show the directory in the xterm title
+echo -n "\033]2;tcsh: $cwd\007"
+
+# Interferes with running commands
+unset printexitvalue
+
+# For sanity
+set backslash_quote
+
+# stat would be better/faster, but stat is about as unportable as it gets
+alias __pstat 'perl -e \'print((stat($ARGV[0]))[9])\''
+
+# Some games for the sake of efficiency
+if ( $?reporoot ) then
+	if ( "$cwd" =~ "$reporoot*" ) then
+		if ( $repotype == 'git' && $repochanged == `__pstat "$reporoot"/.git/HEAD` ) then
+			goto end
+		endif
+		if ( $repotype == 'hg' && $repochanged == `__pstat "$reporoot"/.hg/branch` ) then
+			goto end
+		endif
+	else
+		unset repotype
+		unset reporoot
+		unset repochanged
+	endif
+endif
+
+if ( ! $?repotype ) set repotype = ''
+
+# Mercurial
+if ( ! $?reporoot || $repotype == 'hg' ) then
+	hg branch >& /dev/null
+	if ( $? == 0 ) then
+		set reporoot = `hg root`
+		set repotype = 'hg'
+		set repochanged = `__pstat "$reporoot"/.hg/branch`
+		set prompt = "[%~](`cat $reporoot/.hg/branch`)%# "
+
+		goto end
+	endif
+endif
+
+
+# Git
+if ( ! $?reporoot || $repotype == 'git' ) then
+	git rev-parse --abbrev-ref HEAD >& /dev/null
+	if ( $? == 0 ) then
+		set reporoot = `git rev-parse --show-toplevel`
+		set repotype = 'git'
+		set repochanged = `__pstat "$reporoot"/.git/HEAD`
+		set prompt = "[%~](`git rev-parse --abbrev-ref HEAD`)%# "
+
+		goto end
+	endif
+endif
+
+
+# We're not in a repo anymore; reset.
+set prompt = "[%~]%# "
+unset repotype
+unset reporoot
+unset repochanged
+
+
+# Cleanup
+end:
+	set printexitvalue
+	unset backslash_quote
+	unalias __pstat