summaryrefslogtreecommitdiff
path: root/.yashrc
blob: 4cf14c5e8ad634cca13f6ed05fe34d767c8a78bd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
_ps1_prompt() {
	cmd_status=$?
	cmd_duration=$((CMD_DURATION / 1000))
	CMD_DURATION=0
	is_git=$(git rev-parse --is-inside-work-tree 2>/dev/null)

	printf '\n\\foc.'
	if [ "$is_git" ]; then
		printf '%s' "$(git rev-parse --show-toplevel | awk -F/ '{ print $NF }')"
		git_path=$(git rev-parse --show-prefix)
		git_path="${git_path%/}"
		[ "$git_path" ] && printf '/%s' "$git_path"
	else
		printf '%s' "$(pwd | sed "s#^$HOME#~#")"
	fi
	printf '\\fD.'

	if [ "$is_git" ]; then
		printf ' on \\fom. %s' "$(git branch --show-current)"

		stat=
		s=$(git status --porcelain -b)
		echo "$s" | grep -q '^U[UDA]|^AA|^DD|^[DA]U'      && stat="$stat="
		git rev-parse --verify refs/stash >/dev/null 2>&1 && stat="$stat\$"
		echo "$s" | grep -q '^[MARCDU ]D|^D[ UM]'         && stat="$stat✘"
		echo "$s" | grep -q '^R[ MD]'                     && stat="$stat»"
		echo "$s" | grep -q '^[ MARC]M'                   && stat="$stat!"
		echo "$s" | grep -q '^A[ MDAU]|^M[ MD]|^UA'       && stat="$stat+"
		echo "$s" | grep -q '^\?\?'                       && stat="$stat?"

		ahead=
		behind=
		echo "$s" | grep -q '^## [^ ]\+ .*ahead' && ahead=1
		echo "$s" | grep -q '^## [^ ]\+ .*behind' && behind=1
		if [ "$ahead" ] && [ "$behind" ]; then
			stat="$stat⇕"
		elif [ "$ahead" ]; then
			stat="$stat⇡"
		elif [ "$behind" ]; then
			stat="$stat⇣"
		fi

		if [ "$stat" ]; then
			printf '\\for. [%s]' "$stat"
		fi
	fi

	if [ "$cmd_duration" -gt 1 ]; then
		printf ' took\\foy.'

		secs=$((cmd_duration % 60))
		mins=$((cmd_duration / 60 % 60))
		hours=$((cmd_duration / 3600))

		[ "$hours" -gt 0 ] && printf ' %dh' "$hours"
		[ "$mins" -gt 0 ] && printf ' %dm' "$mins"
		[ "$secs" -gt 0 ] && printf ' %ds' "$secs"
	fi
	printf '\\fD.\n'

	n_jobs="$(jobs 2>/dev/null | wc -l)"
	if [ "$n_jobs" -gt 0 ]; then
		printf '\\fob.✦ '
		[ "$n_jobs" -gt 1 ] && printf '%d ' "$n_jobs"
		printf '\\fD.'
	fi

	if [ "$cmd_status" -eq 0 ]; then
		printf '\\fg.'
	else
		printf '\\fr.'
	fi
	printf '❯ \\fD.'
}

export PS1='$(_ps1_prompt)'

export HISTSIZE=100000
export HISTRMDUP=10

set le-predict

alias cfg='git --git-dir ~/.cfg --work-tree ~'