-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathinit.fish
70 lines (59 loc) · 2.23 KB
/
init.fish
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
# Fish <2.2.0
if printf '%s\n2.2.0' "$FISH_VERSION" | sort --check=silent --version-sort
for line in (cat (dirname (status -f))/abbreviations)
# 1. Strip out comments
# 2. Squeeze repeating spaces
# 3. Strip trailing whitespaces
set line (echo "$line" | cut -d '#' -f 1 | tr -s ' ' | sed 's/[[:space:]]*$//')
# Skip empty lines
if not [ "$line" ]; continue; end
# Parse lines
set key (echo "$line" | cut -d ' ' -f 1)
set value (echo "$line" | cut -d ' ' -f 2-)
alias $key $value
end
exit
end
# Skip if cgitc_revision is up to date
set -l current_revision (git -C (dirname (realpath (status -f))) rev-parse HEAD)
if [ "$cgitc_revision" != "$current_revision" ]
printf 'Initializing \x1b[33mcgitc\x1b[0m ... '
if printf '%s\n3.0.0' "$FISH_VERSION" | sort --check=silent --version-sort
# Fish >=2.2.0, <3.0.0
# Use fish_user_abbreviations environment variable
set -l cgitc_text (
for line in (cat (dirname (realpath (status -f)))/abbreviations)
# 1. Strip out comments
# 2. Squeeze repeating spaces
# 3. Strip trailing whitespaces
set line (echo "$line" | cut -d '#' -f 1 | tr -s ' ' | sed 's/[[:space:]]*$//')
# Skip empty lines
if not [ "$line" ]; continue; end
# Wrap with double quote
echo "\"$line\""
end | tr '\n' ' '
)
echo "set -gx fish_user_abbreviations \$fish_user_abbreviations $cgitc_text" > (realpath (dirname (status -f)))/run.fish
else
# Fish >=3.0.0
# Use abbr command
set -l cgitc_text (
for line in (cat (dirname (realpath (status -f)))/abbreviations)
# 1. Strip out comments
# 2. Squeeze repeating spaces
# 3. Strip trailing whitespaces
set line (echo "$line" | cut -d '#' -f 1 | tr -s ' ' | sed 's/[[:space:]]*$//')
# Skip empty lines
if not [ "$line" ]; continue; end
# Tokenize
set line (string split ' ' $line)
# Wrap with calling 'abbr'
echo "abbr --add --global -- $line[1] \"$line[2..-1]\""
end
)
echo -s \n$cgitc_text > (realpath (dirname (status -f)))/run.fish
end
set -U cgitc_revision "$current_revision"
echo 'Done'
end
source (realpath (dirname (status -f)))/run.fish