multi-user support
This commit is contained in:
parent
b9556cd842
commit
d4fe4f2d8b
11
README.md
11
README.md
@ -65,6 +65,13 @@ An automatic configuration program for vim
|
||||
为防止vimplus显示乱码,需设置linux终端字体为`Droid Sans Mono Nerd Font`。
|
||||
|
||||
|
||||
#### 多用户支持
|
||||
|
||||
将vimplus在某个用户下安装好后,若需要在其他用户也能够使用vimplus,则执行
|
||||
|
||||
sudo ./install_to_user.sh username1 username2
|
||||
|
||||
|
||||
## 个性化
|
||||
|
||||
修改 `~/.vimrc.local` 文件内容,以启用个性化定制,可覆盖 `~/.vimrc` 中的设置。
|
||||
@ -193,10 +200,6 @@ An automatic configuration program for vim
|
||||
|
||||
vimplus安装完毕之后,`~`目录下将会生成两个隐藏文件分别是.vimrc和.ycm_extra_conf.py,其中.vimrc是vim的配置文件,.ycm_extra_conf.py是ycm插件的配置文件,当你需要创建一个project时,需要将.ycm_extra_conf.py拷贝到project的顶层目录,通过修改该配置文件里面的`flags`变量来添加你的第三方库路径。
|
||||
|
||||
- **`在A用户下安装了vimplus,在B用户下不能使用?`**
|
||||
|
||||
目前vimplus是基于用户的,如果你想在其他用户下也能使用vimplus,也需要单独安装。
|
||||
|
||||
- **`怎么自定义文件头,比如说添加作者、创建时间?`**
|
||||
|
||||
你可以修改[chxuan/prepare-code][67]插件来达到目的,可以参考[这里][77]。
|
||||
|
||||
167
install_to_user.sh
Executable file
167
install_to_user.sh
Executable file
@ -0,0 +1,167 @@
|
||||
#!/bin/bash
|
||||
|
||||
# 获取平台类型,mac还是linux平台
|
||||
function get_platform_type()
|
||||
{
|
||||
echo $(uname)
|
||||
}
|
||||
|
||||
# 在linux上获取当前用户
|
||||
function get_current_username_on_linux()
|
||||
{
|
||||
current_path=$PWD
|
||||
array=(${current_path//// })
|
||||
|
||||
if [ ${array[0]} == "root" ]; then
|
||||
echo ${array[0]}
|
||||
else
|
||||
echo ${array[1]}
|
||||
fi
|
||||
}
|
||||
|
||||
# 在linux上判断用户是否存在
|
||||
function is_valid_user_on_linux()
|
||||
{
|
||||
desc_username=$1
|
||||
usernames=$(ls /home/)
|
||||
array=(${usernames// / })
|
||||
|
||||
is_found=0
|
||||
for username in ${array[@]}
|
||||
do
|
||||
if [ $username == $desc_username ]; then
|
||||
is_found=1
|
||||
break
|
||||
fi
|
||||
done
|
||||
|
||||
if [ $desc_username == "root" ]; then
|
||||
is_found=1
|
||||
fi
|
||||
|
||||
echo $is_found
|
||||
}
|
||||
|
||||
# 打印logo
|
||||
function print_logo()
|
||||
{
|
||||
color="$(tput setaf 6)"
|
||||
normal="$(tput sgr0)"
|
||||
printf "${color}"
|
||||
echo ' __ __ '
|
||||
echo '__ __/_/___ ___ ____ / /_ _______ '
|
||||
echo '\ \ / / / __ `__ \/ __ \/ / / / / ___/ '
|
||||
echo ' \ V / / / / / / / /_/ / / /_/ (__ ) '
|
||||
echo ' \_/_/_/ /_/ /_/ ,___/_/\____/____/ '
|
||||
echo ' /_/ ...is now installed!'
|
||||
echo ''
|
||||
echo ''
|
||||
echo 'Just enjoy it!'
|
||||
echo 'p.s. Follow me at https://github.com/chxuan.'
|
||||
echo ''
|
||||
printf "${normal}"
|
||||
}
|
||||
|
||||
# 获得home路径
|
||||
function get_home_path()
|
||||
{
|
||||
username=$1
|
||||
if [ $username == "root" ]; then
|
||||
echo "/root/"
|
||||
else
|
||||
echo "/home/"$username"/"
|
||||
fi
|
||||
}
|
||||
|
||||
# 在linux上将vimplus安装到指定用户
|
||||
function install_to_user_on_linux()
|
||||
{
|
||||
src_username=`get_current_username_on_linux`
|
||||
desc_username=$1
|
||||
|
||||
# 判断是否是有效用户
|
||||
is_found=$(is_valid_user_on_linux $desc_username)
|
||||
if [ $is_found != 1 ]; then
|
||||
echo "Invalid username "$desc_username
|
||||
return
|
||||
fi
|
||||
|
||||
# 判断是否是当前用户
|
||||
if [ $src_username == $desc_username ]; then
|
||||
echo "Can not install vimplus to "$desc_username
|
||||
return
|
||||
fi
|
||||
|
||||
src_home_path=$(get_home_path $src_username)
|
||||
desc_home_path=$(get_home_path $desc_username)
|
||||
|
||||
echo "Current home path:"$src_home_path
|
||||
echo "Installing vimplus to "$desc_home_path
|
||||
|
||||
# 拷贝.vim目录
|
||||
src_vim_path=$src_home_path".vim/"
|
||||
desc_vim_path=$desc_home_path".vim/"
|
||||
|
||||
rm -rf $desc_vim_path
|
||||
mkdir $desc_vim_path
|
||||
|
||||
cp -R $src_vim_path"autoload/" $desc_vim_path
|
||||
cp -R $src_vim_path"plugged/" $desc_vim_path
|
||||
|
||||
chown -R $desc_username":"$desc_username $desc_vim_path
|
||||
|
||||
# 拷贝.vimplus目录
|
||||
src_vimplus_path=$src_home_path".vimplus/"
|
||||
desc_vimplus_path=$desc_home_path".vimplus/"
|
||||
|
||||
rm -rf $desc_vimplus_path
|
||||
cp -R $src_vimplus_path $desc_home_path
|
||||
chown -R $desc_username":"$desc_username $desc_vimplus_path
|
||||
|
||||
rm -rf $desc_home_path".vimrc.local"
|
||||
cp $desc_vimplus_path".vimrc.local" $desc_home_path
|
||||
chown $desc_username":"$desc_username $desc_home_path".vimrc.local"
|
||||
|
||||
# 创建软链接
|
||||
rm -rf $desc_home_path".vimrc"
|
||||
ln -s $desc_vimplus_path".vimrc" $desc_home_path
|
||||
chown -R $desc_username":"$desc_username $desc_home_path".vimrc"
|
||||
|
||||
rm -rf $desc_home_path".ycm_extra_conf.py"
|
||||
ln -s $desc_vimplus_path".ycm_extra_conf.py" $desc_home_path
|
||||
chown -R $desc_username":"$desc_username $desc_home_path".ycm_extra_conf.py"
|
||||
|
||||
ln -s $desc_vimplus_path"colors" $desc_vim_path
|
||||
chown -R $desc_username":"$desc_username $desc_vim_path"colors"
|
||||
|
||||
ln -s $desc_vimplus_path"ftplugin" $desc_vim_path
|
||||
chown -R $desc_username":"$desc_username $desc_vim_path"ftplugin"
|
||||
|
||||
# 安装字体
|
||||
mkdir $desc_home_path".fonts/"
|
||||
rm -rf $desc_home_path".fonts/Droid Sans Mono Nerd Font Complete.otf"
|
||||
cp $desc_vimplus_path"fonts/Droid Sans Mono Nerd Font Complete.otf" $desc_home_path".fonts/"
|
||||
chown -R $desc_username":"$desc_username $desc_home_path".fonts/"
|
||||
fc-cache -vf $desc_home_path".fonts/"
|
||||
}
|
||||
|
||||
# 脚本启动点
|
||||
if [ $# -lt 1 ]; then
|
||||
echo "Please input username!"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
type=`get_platform_type`
|
||||
echo "Platform type: "${type}
|
||||
|
||||
if [ ${type} == "Linux" ]; then
|
||||
for username in $@
|
||||
do
|
||||
install_to_user_on_linux $username
|
||||
done
|
||||
|
||||
print_logo
|
||||
else
|
||||
echo "Not support platform type: "${type}
|
||||
fi
|
||||
|
||||
Loading…
Reference in New Issue
Block a user