Ver Código Fonte

~/.zshrc,~/.bin/since.go: Display exit code if command fails

Lu Stadler 5 anos atrás
pai
commit
69b02fd8ba
2 arquivos alterados com 8 adições e 2 exclusões
  1. 6 1
      .bin/since.go
  2. 2 1
      .zshrc

+ 6 - 1
.bin/since.go

@ -21,6 +21,7 @@ var commandBlacklist = []string{
21 21
func main() {
22 22
	last := os.Args[1]
23 23
	cmdName := os.Args[2]
24
	exitStatus := os.Args[3]
24 25
	t, err := time.Parse(time.RFC3339Nano, last)
25 26
	if err != nil {
26 27
		return
@ -31,7 +32,11 @@ func main() {
31 32
		// notify window manager (bell character, some window managers/terminals mark when it appears)
32 33
		fmt.Printf("\a")
33 34
		// send notification for long-running commands
34
		cmd := exec.Command("notify-send", fmt.Sprintf("%q done", cmdName), fmt.Sprintf("took %s", dur))
35
		statusInfo := "done"
36
		if exitStatus != "0" {
37
			statusInfo = fmt.Sprintf("failed (%s)", exitStatus)
38
		}
39
		cmd := exec.Command("notify-send", fmt.Sprintf("%q %s", cmdName, statusInfo), fmt.Sprintf("took %s", dur))
35 40
		cmd.Start()
36 41
	}
37 42
	fmt.Printf("(%s) ", dur)

+ 2 - 1
.zshrc

@ -41,10 +41,11 @@ __last_cmd_time=""
41 41
42 42
autoload colors && colors
43 43
function precmd {
44
	last_exit="$?"
44 45
	echo -ne "\033]0;\007"
45 46
	user="%{$fg[red]%}%n%{$reset_color%}"
46 47
	dir="%{$fg[cyan]%}%~%{$reset_color%}"
47
	duration=$(since "$__last_cmd_time" "$history[$(($HISTCMD-1))]")
48
	duration=$(since "$__last_cmd_time" "$history[$(($HISTCMD-1))]" "$last_exit")
48 49
	# store last cmd in psvar[1] (magically avoids escaping problems?)
49 50
	psvar[1]="$history[$(($HISTCMD-1))]"
50 51
	if [ -n "$SSH_CONNECTION" ]; then