mirror of
https://github.com/SpaceVim/SpaceVim.git
synced 2025-01-23 07:10:06 +08:00
feat:(XDG): add XDG support
* fonts: Ensure mkfontscale is installed When installing fonts, we have a silent igored error about missing `mkfontscale` (and `mkfontdir`). Add a requirements check for it, and 'need' it when actually attempting to install fonts. * fetch_repo: Never change a directory It is bad practice to change the currents shell working directory. E.g. never use 'cd' in a script. For example, if `git pull` crashes, it would leave the user in the git directory 'somewhere' on his filesystem, potentially causing confusion, as the following `cd -` command is never executed. There are of course always exceptions, such as when tooling does not (easily) support out of tree invocation. To solve this, run the command in a subshell, which won't touch the current working directory as the exit of the subshell kept the previous working directory. A more difficult alternative would be to pass `--git-dir` and `--work-tree` along to git, but this would make it far harder to read. * fetch_repo: Do not duplicate code all over There is no reason to put `need 'git'` all over the place, when the only time we truly need it, is if we pull the repo. Make the code a little less cluttered and a bit easier to read. * install: Support XDG_CONFIG_HOME Add support for the XDG specification for XDG_CONFIG_HOME. NeoVIM already follows this, regular vim needs a bit of help there. Closes: #3517 * SpaceVim.d: Support XDG paths Signed-off-by: Olliver Schinagl <oliver@schinagl.nl> Signed-off-by: Olliver Schinagl <oliver@schinagl.nl>
This commit is contained in:
parent
09bffd93c0
commit
9e80d9bbfa
@ -62,7 +62,11 @@ endfunction
|
||||
|
||||
function! s:global_dir() abort
|
||||
if empty($SPACEVIMDIR)
|
||||
return s:FILE.unify_path('~/.SpaceVim.d/')
|
||||
if !empty($XDG_CONFIG_HOME)
|
||||
return s:FILE.unify_path($XDG_CONFIG_HOME.'/SpaceVim.d/')
|
||||
else
|
||||
return s:FILE.unify_path($HOME.'/.SpaceVim.d/')
|
||||
endif
|
||||
else
|
||||
return s:FILE.unify_path($SPACEVIMDIR)
|
||||
endif
|
||||
|
100
docs/install.sh
100
docs/install.sh
@ -89,6 +89,10 @@ Version='2.1.0-dev'
|
||||
System="$(uname -s)"
|
||||
# }}}
|
||||
|
||||
XDGSpaceDir="${XDG_CONFIG_HOME:-${HOME}/.}${XDG_CONFIG_HOME:+/}SpaceVim"
|
||||
XDGvimDir="${XDG_CONFIG_HOME:-${HOME}/.}${XDG_CONFIG_HOME:+/}vim"
|
||||
XDGnvimDir="${XDG_CONFIG_HOME:-${HOME}/.}${XDG_CONFIG_HOME:+/}nvim"
|
||||
|
||||
# need_cmd {{{
|
||||
need_cmd () {
|
||||
if ! hash "$1" &>/dev/null; then
|
||||
@ -129,15 +133,17 @@ echo_with_color () {
|
||||
|
||||
# fetch_repo {{{
|
||||
fetch_repo () {
|
||||
if [[ -d "$HOME/.SpaceVim" ]]; then
|
||||
need_cmd 'git'
|
||||
if [[ -d "${XDGSpaceDir:-}" ]]; then
|
||||
info "Trying to update SpaceVim"
|
||||
cd "$HOME/.SpaceVim"
|
||||
git pull
|
||||
cd - > /dev/null 2>&1
|
||||
(
|
||||
cd "${XDGSpaceDir:?}"
|
||||
git pull
|
||||
)
|
||||
success "Successfully update SpaceVim"
|
||||
else
|
||||
info "Trying to clone SpaceVim"
|
||||
git clone https://github.com/SpaceVim/SpaceVim.git "$HOME/.SpaceVim"
|
||||
git clone https://github.com/SpaceVim/SpaceVim.git "${XDGSpaceDir:-}"
|
||||
if [ $? -eq 0 ]; then
|
||||
success "Successfully clone SpaceVim"
|
||||
else
|
||||
@ -155,51 +161,47 @@ install_vim () {
|
||||
success "Backup $HOME/.vimrc to $HOME/.vimrc_back"
|
||||
fi
|
||||
|
||||
if [[ -d "$HOME/.vim" ]]; then
|
||||
if [[ "$(readlink $HOME/.vim)" =~ \.SpaceVim$ ]]; then
|
||||
success "Installed SpaceVim for vim"
|
||||
else
|
||||
mv "$HOME/.vim" "$HOME/.vim_back"
|
||||
success "BackUp $HOME/.vim to $HOME/.vim_back"
|
||||
ln -s "$HOME/.SpaceVim" "$HOME/.vim"
|
||||
success "Installed SpaceVim for vim"
|
||||
if [[ -d "${XDGvimDir:-}" ]]; then
|
||||
if [[ "$(readlink "${XDGvimDir:-}")" =~ \.?SpaceVim$ ]]; then
|
||||
success "SpaceVim already installed in '${XDGvimDir:-}'"
|
||||
return
|
||||
fi
|
||||
else
|
||||
ln -s "$HOME/.SpaceVim" "$HOME/.vim"
|
||||
success "Installed SpaceVim for vim"
|
||||
|
||||
mv "${XDGvimDir:?}" "${XDGvimDir:-}_back"
|
||||
success "BackUp '${XDGvimDir}' to '${XDGvimDir}_back'"
|
||||
fi
|
||||
|
||||
ln -s "${XDGSpaceDir:?}" "${XDGvimDir:?}"
|
||||
success "Installed SpaceVim for vim in '${XDGvimDir}'"
|
||||
}
|
||||
# }}}
|
||||
|
||||
# install_neovim {{{
|
||||
install_neovim () {
|
||||
if [[ -d "$HOME/.config/nvim" ]]; then
|
||||
if [[ "$(readlink $HOME/.config/nvim)" =~ \.SpaceVim$ ]]; then
|
||||
success "Installed SpaceVim for neovim"
|
||||
else
|
||||
mv "$HOME/.config/nvim" "$HOME/.config/nvim_back"
|
||||
success "BackUp $HOME/.config/nvim to $HOME/.config/nvim_back"
|
||||
ln -s "$HOME/.SpaceVim" "$HOME/.config/nvim"
|
||||
success "Installed SpaceVim for neovim"
|
||||
if [[ -d "${XDGnvimDir:-}" ]]; then
|
||||
if [[ "$(readlink "${XDGnvimDir:-}")" =~ \.?SpaceVim$ ]]; then
|
||||
success "SpaceVim already installed in '${XDGnvimDir:-}'"
|
||||
return
|
||||
fi
|
||||
else
|
||||
mkdir -p "$HOME/.config"
|
||||
ln -s "$HOME/.SpaceVim" "$HOME/.config/nvim"
|
||||
success "Installed SpaceVim for neovim"
|
||||
|
||||
mv "${XDGnvimDir:?}" "${XDGnvimDir:-}_back"
|
||||
success "BackUp '${XDGnvimDir}' to '${XDGnvimDir}_back'"
|
||||
fi
|
||||
|
||||
ln -s "${XDGSpaceDir:?}" "${XDGnvimDir:?}"
|
||||
success "Installed SpaceVim for nvim in '${XDGnvimDir}'"
|
||||
}
|
||||
# }}}
|
||||
|
||||
# uninstall_vim {{{
|
||||
uninstall_vim () {
|
||||
if [[ -d "$HOME/.vim" ]]; then
|
||||
if [[ "$(readlink $HOME/.vim)" =~ \.SpaceVim$ ]]; then
|
||||
rm "$HOME/.vim"
|
||||
success "Uninstall SpaceVim for vim"
|
||||
if [[ -d "$HOME/.vim_back" ]]; then
|
||||
mv "$HOME/.vim_back" "$HOME/.vim"
|
||||
success "Recover from $HOME/.vim_back"
|
||||
fi
|
||||
if [[ -d "${XDGvimDir:-}" ]] &&
|
||||
[[ "$(readlink "${XDGvimDir:?}")" =~ \.?SpaceVim$ ]]; then
|
||||
rm "${XDGvimDir:?}"
|
||||
success "Uninstall SpaceVim for vim"
|
||||
if [[ -d "${XDGvimDir}_back" ]]; then
|
||||
mv "${XDGvimDir}_back" "${XDGvimDir}"
|
||||
success "Recover from ${XDGvimDir}_back"
|
||||
fi
|
||||
fi
|
||||
if [[ -f "$HOME/.vimrc_back" ]]; then
|
||||
@ -211,14 +213,13 @@ uninstall_vim () {
|
||||
|
||||
# uninstall_neovim {{{
|
||||
uninstall_neovim () {
|
||||
if [[ -d "$HOME/.config/nvim" ]]; then
|
||||
if [[ "$(readlink $HOME/.config/nvim)" =~ \.SpaceVim$ ]]; then
|
||||
rm "$HOME/.config/nvim"
|
||||
success "Uninstall SpaceVim for neovim"
|
||||
if [[ -d "$HOME/.config/nvim_back" ]]; then
|
||||
mv "$HOME/.config/nvim_back" "$HOME/.config/nvim"
|
||||
success "Recover from $HOME/.config/nvim_back"
|
||||
fi
|
||||
if [[ -d "${XDGnvimDir:-}" ]] &&
|
||||
[[ "$(readlink "${XDGnvimDir:?}")" =~ \.?SpaceVim$ ]]; then
|
||||
rm "${XDGnvimDir:?}"
|
||||
success "Uninstall SpaceVim for neovim"
|
||||
if [[ -d "${XDGnvimDir}_back" ]]; then
|
||||
mv "${XDGnvimDir}_back" "${XDGnvimDir}"
|
||||
success "Recover from ${XDGnvimDir}_back"
|
||||
fi
|
||||
fi
|
||||
}
|
||||
@ -233,6 +234,12 @@ check_requirements () {
|
||||
else
|
||||
warn "Check Requirements : git"
|
||||
fi
|
||||
if hash "mkfontscale" &>/dev/null; then
|
||||
mkfontscale_version=$(mkfontscale -v)
|
||||
success "Check Requirements: ${mkfontscale_version}"
|
||||
else
|
||||
warn "Check Requirements : mkfontscale"
|
||||
fi
|
||||
if hash "vim" &>/dev/null; then
|
||||
is_vim8=$(vim --version | grep "Vi IMproved 8")
|
||||
is_vim74=$(vim --version | grep "Vi IMproved 7.4")
|
||||
@ -346,6 +353,8 @@ download_font () {
|
||||
|
||||
# install_fonts {{{
|
||||
install_fonts () {
|
||||
need_cmd 'mkfontdir'
|
||||
need_cmd 'mkfontscale'
|
||||
if [[ ! -d "$HOME/.local/share/fonts" ]]; then
|
||||
mkdir -p $HOME/.local/share/fonts
|
||||
fi
|
||||
@ -383,7 +392,6 @@ main () {
|
||||
;;
|
||||
--install|-i)
|
||||
welcome
|
||||
need_cmd 'git'
|
||||
fetch_repo
|
||||
if [ $# -eq 2 ]
|
||||
then
|
||||
@ -413,7 +421,6 @@ main () {
|
||||
;;
|
||||
--no-fonts)
|
||||
welcome
|
||||
need_cmd 'git'
|
||||
fetch_repo
|
||||
install_vim
|
||||
install_neovim
|
||||
@ -426,7 +433,6 @@ main () {
|
||||
esac
|
||||
else
|
||||
welcome
|
||||
need_cmd 'git'
|
||||
fetch_repo
|
||||
install_vim
|
||||
install_neovim
|
||||
|
20
vimrc
20
vimrc
@ -6,6 +6,26 @@
|
||||
" License: GPLv3
|
||||
"=============================================================================
|
||||
|
||||
" Use XDG paths if available
|
||||
if !empty($XDG_CONFIG_HOME)
|
||||
set runtimepath^=$XDG_CONFIG_HOME/vim
|
||||
set runtimepath+=$XDG_DATA_HOME/vim
|
||||
set runtimepath+=$XDG_CONFIG_HOME/vim/after
|
||||
|
||||
set packpath^=$XDG_DATA_HOME/vim,$XDG_CONFIG_HOME/vim
|
||||
set packpath+=$XDG_CONFIG_HOME/vim/after,$XDG_DATA_HOME/vim/after
|
||||
|
||||
let g:netrw_home = $XDG_DATA_HOME."/vim"
|
||||
call mkdir($XDG_DATA_HOME."/vim/spell", 'p')
|
||||
|
||||
set backupdir=$XDG_STATE_HOME/vim/backup | call mkdir(&backupdir, 'p')
|
||||
set directory=$XDG_STATE_HOME/vim/swap | call mkdir(&directory, 'p')
|
||||
set undodir=$XDG_STATE_HOME/vim/undo | call mkdir(&undodir, 'p')
|
||||
set viewdir=$XDG_STATE_HOME/vim/view | call mkdir(&viewdir, 'p')
|
||||
|
||||
if !has('nvim') | set viminfofile=$XDG_STATE_HOME/vim/viminfo | endif
|
||||
endif
|
||||
|
||||
" Note: Skip initialization for vim-tiny or vim-small.
|
||||
if 1
|
||||
let g:_spacevim_if_lua = 0
|
||||
|
Loading…
Reference in New Issue
Block a user