Просмотр исходного кода

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

Lu Stadler лет назад: 5
Родитель
Сommit
69b02fd8ba
2 измененных файлов с 8 добавлено и 2 удалено
  1. 6 1
      .bin/since.go
  2. 2 1
      .zshrc

+ 6 - 1
.bin/since.go

21
func main() {
21
func main() {
22
	last := os.Args[1]
22
	last := os.Args[1]
23
	cmdName := os.Args[2]
23
	cmdName := os.Args[2]
24
	exitStatus := os.Args[3]
24
	t, err := time.Parse(time.RFC3339Nano, last)
25
	t, err := time.Parse(time.RFC3339Nano, last)
25
	if err != nil {
26
	if err != nil {
26
		return
27
		return
31
		// notify window manager (bell character, some window managers/terminals mark when it appears)
32
		// notify window manager (bell character, some window managers/terminals mark when it appears)
32
		fmt.Printf("\a")
33
		fmt.Printf("\a")
33
		// send notification for long-running commands
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
		cmd.Start()
40
		cmd.Start()
36
	}
41
	}
37
	fmt.Printf("(%s) ", dur)
42
	fmt.Printf("(%s) ", dur)

+ 2 - 1
.zshrc

41
41
42
autoload colors && colors
42
autoload colors && colors
43
function precmd {
43
function precmd {
44
	last_exit="$?"
44
	echo -ne "\033]0;\007"
45
	echo -ne "\033]0;\007"
45
	user="%{$fg[red]%}%n%{$reset_color%}"
46
	user="%{$fg[red]%}%n%{$reset_color%}"
46
	dir="%{$fg[cyan]%}%~%{$reset_color%}"
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
	# store last cmd in psvar[1] (magically avoids escaping problems?)
49
	# store last cmd in psvar[1] (magically avoids escaping problems?)
49
	psvar[1]="$history[$(($HISTCMD-1))]"
50
	psvar[1]="$history[$(($HISTCMD-1))]"
50
	if [ -n "$SSH_CONNECTION" ]; then
51
	if [ -n "$SSH_CONNECTION" ]; then