-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinit.fish
executable file
·124 lines (117 loc) · 4.39 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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
#!/usr/bin/env fish
function block_key
echo -e "Input any key to continue: "
read wait
end
# Check whether `__fish_config_dir` exists
# If not find `__fish_config_dir`, make this dir and set default `__fish_config_dir` to `$HOME/.config/fish`
echo "==> Find `__fish_config_dir`"
if not set -q __fish_config_dir
echo 'Cannot find variable, __fish_config_dir'
printf "Do you want to `mkdir -p %s`, and set it as __fish_config_dir?(y/n)\n" "$HOME/.config/fish"
read choice
if test "$choice" = "y"
printf "Set var __fish_config_dir as `%s` and create the dir\n" "$__fish_config_dir"
mkdir -p {$HOME}/.config/fish
set -Ux __fish_config_dir {$HOME}/.config/fish
else
echo "Con NOT find `__fish_config_dir`, EXIT;"
exit
end
else
printf "Find `__fish_config_dir`: %s\n" "$__fish_config_dir"
end
echo "==> Finish finding `__fish_config_dir`"
block_key
# Set local variable
set -l cwd (dirname (readlink -m (status --current-filename)))
set -l custom_file {$cwd}/config.fish
set -l config_file {$__fish_config_dir}/config.fish
printf "==> Deal with `%s`\n" "$config_file"
if not test -e $config_file
printf "Can NOT fund config file: `%s`\n" "$config_file"
echo "Do you want to create it?(y/n)"
read create_config
if test "$create_config" = "y"
printf "Creating config file: %s\n" "$config_file"
touch "$config_file"
else
printf "Can NOT find config file: %s. EXIT;" "$config_file"
exit
end
end
set -l config_content (cat $config_file)
if string match -r ".*$custom_file.*" $config_content 1> /dev/null
printf "Find %s in %s\n" "$custom_file" "$config_file"
echo "Init has finished. EXIT;"
exit
else
echo "Write the following command into $config_file"
echo ''
echo '# source dotfile from ulic-youthlic/fish.conf' >> $config_file
echo '# source dotfile from ulic-youthlic/fish.conf'
printf "source %s\n" "$custom_file" >> $config_file
printf "source %s\n" "$custom_file"
echo ''
end
echo "==> Finish dealing with %s" $config_file
block_key
# check whether wsl env or not
echo "==> Deal with WSL env"
set -l wsl_file "$__fish_config_dir/.wsl"
echo "This configuration will impact on fish function `proxy` and `unproxy`"
if not test -e $wsl_file
echo 'Is it wsl?(y/n)'
read wsl
if test "$wsl" = "y"
printf "Create sign file: %s\n" "$wsl_file"
touch "$wsl_file"
end
else
printf "Find file `%s`\n" "$wsl_file"
echo "Confirm fish running in the wsl env"
end
echo "==> Finish dealing with WSL env"
block_key
# Deal with plugins file
set -l old_plugins {$__fish_config_dir}/fish_plugins
set -l new_plugins {$cwd}/fish_plugins
printf "==> Deal with fish_plugins file: %s\n" "$old_plugins"
echo "This configuration use `fisher` as fish plugin manager"
if not test -e $old_plugins
printf "Not find fish_plugins file for `fisher`, creating symlink from %s to %s\n" "$new_plugins" "$old_plugins"
else
printf "Find fish_plugins file for `fisher`, appending it to %s, creating symlink from %s to %s\n" "$new_plugins" "$new_plugins" "$old_plugins"
cat $old_plugins >> $new_plugins
rm $old_plugins
end
ln -s $new_plugins $old_plugins
printf "==> Finish deal with fish_plugins file: %s\n" "$old_plugins"
block_key
# Set fish as default shell
set -l default_shell (awk -F: -v user=(whoami) '$1 == user {print $NF}' /etc/passwd)
echo "==> Deal with default shell"
if string match --regex "bash" "$default_shell" 1> /dev/null; or string match --regex "zsh" "$default_shell" 1> /dev/null
echo "Default shell is $default_shell"
echo "Does you want to make bash launch fish shell automatically when bash launched?(y/n)"
read confirm
if test "$confirm" = "y"
printf "Append the following into your `%s/.bashrc`\n" "$HOME"
echo ''
cat $cwd/bashrc.sample >> $HOME/.bashrc
cat $cwd/bashrc.sample
echo ''
end
end
echo "==> Finish dealing with default shell"
# Init finished
echo "Init finished"
echo "The following thing is recommanded:"
echo ''
printf " 1. Set `BASE_CONFIG_DIR` env var in your %s.\n" "$config_file"
printf " set -gx BASE_CONFIG_DIR '<path/to/base.conf/dir>' # Appending this line to %s\n" "$config_file"
echo " # If you donot know what is base.conf doing, see README.md"
echo " 2. Update your fish plugins, or install fisher first."
echo " \$ fisher update"
echo ""
echo "Thank you for using this configuration."