基于 Ubuntu 18.04 的自动装机脚本

作者:解琛
时间:2020 年 6 月 11 日

  • 一、资源地址
  • 二、vim markdown 表格支持
  • 三、vim 设置默认的系统剪切板

一、资源地址

搜狗输入法
vimplus
ranger 图标插件
ranger 配置说明
百度网盘

二、vim markdown 表格支持

Plug dhruvasagar/vim-table-mode

let g:table_mode_corner = '|'
let g:table_mode_border=0
let g:table_mode_fillchar=' '

function! s:isAtStartOfLine(mapping)
  let text_before_cursor = getline('.')[0 : col('.')-1]
  let mapping_pattern = '\V' . escape(a:mapping, '\')
  let comment_pattern = '\V' . escape(substitute(&l:commentstring, '%s.*$', '', ''), '\')
  return (text_before_cursor =~? '^' . ('\v(' . comment_pattern . '\v)?') . '\s*\v' . mapping_pattern . '\v$')
endfunction

inoreabbrev  
          \ isAtStartOfLine('\|\|') ?
          \ '<c-o>:TableModeEnable<cr><bar><space><bar><left><left>' : '<bar><bar>'
inoreabbrev  __
          \ isAtStartOfLine('__') ?
          \ '<c-o>:silent! TableModeDisable<cr>' : '__'

三、vim 设置默认的系统剪切板

先进 vim 里面,在 normal 模式下用:reg,查看有没有 + 开头的行,如果没有,则在终端进行安装。

sudo apt install vim-gnome

使用 vimplus 的 y 即可完成系统剪切板的复制。

有了 + 剪切板后,使用以下指令进行确认。

vim --version | grep clipboard

之后修改 vim 的启动文件即可。

set clipboard=unnamedplus

附录:装机脚本


# 更换阿里源;
sudo rm -rvf /etc/apt/sources.list
sudo touch /etc/apt/sources.list
sudo chmod 777 /etc/apt/sources.list
sudo echo "
deb http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse
" >> /etc/apt/sources.list

sudo apt update

# 安装一个终端打印标题的软件;
figlet "figlet"
sudo apt install figlet

# 对系统的中文路径做一个软链接;
figlet "ln"
ln -s /home/jerome/桌面 desktop
ln -s /home/jerome/下载 download
ln -s /home/jerome/文档 documents
mv desktop download documents /home/jerome/
rm -rvf /home/jerome/desktop/桌面 
rm -rvf /home/jerome/download/下载
rm -rvf /home/jerome/documents/文档

# 安装 google 浏览器;
figlet "chrome"
sudo wget http://www.linuxidc.com/files/repo/google-chrome.list -P /etc/apt/sources.list.d/
wget -q -O - https://dl.google.com/linux/linux_signing_key.pub  | sudo apt-key add -
sudo apt update
sudo apt install google-chrome-stable
sudo rm -rvf /etc/apt/sources.list.d/*

# 新建一个脚本文件夹;
# mkdir /home/jerome/desktop/_bash

# 新开一个终端开始安装 vimplus 编辑器;
# figlet 'vimplus'
# touch /home/jerome/desktop/_bash/vim_install.sh
# echo "
figlet 'vimplus'
sudo apt install git
sudo apt install vim
sudo apt install python2 python3
sudo apt install debconf gnupg 
# git clone https://github.com/KylinskyChen/vimplus.git ~/.vimplus
# 这个下载实在太慢还容易崩溃,直接下载一个更好。
bash /home/jerome/.vimplus/install.sh
# " >> /home/jerome/desktop/_bash/vim_install.sh
# sudo chmod +x /home/jerome/desktop/_bash/vim_install.sh
# gnome-terminal --window -e 'bash -c "sudo bash /home/jerome/desktop/_bash/vim_install.sh;exec bash"'

# 安装 ranger;
figlet 'ranger'
sudo apt-get install ranger     	# ranger 的主程序
sudo apt-get install caca-utils 	# img2txt 图片
sudo apt-get install highlight  	# 代码高亮
sudo apt-get install atool      	# 存档预览
sudo apt-get install w3m        	# html页面预览
sudo apt-get install python-poppler    	# pdf预览
sudo apt-get install mediainfo  	# 多媒体文件预览
sudo apt-get install catdoc     	# doc预览
sudo apt-get install docx2txt  	 	# docx预览
sudo apt-get install xlsx2csv   	# xlsx预览
ranger --copy-config=all
echo "
map D shell trash %s
" >> ~/.config/ranger/rc.conf

echo "
class extract(Command):
    def execute(self):
        import os
        fail=[]
        for i in self.fm.thistab.get_selection():
            ExtractProg='7z x'
            if i.path.endswith('.zip'):
                # zip encoding issue
                ExtractProg='unzip -O gbk'
            elif i.path.endswith('.tar.gz'):
                ExtractProg='tar xvf'
            elif i.path.endswith('.tar.xz'):
                ExtractProg='tar xJvf'
            elif i.path.endswith('.tar.bz2'):
                ExtractProg='tar xjvf'
            if os.system('{0} "{1}"'.format(ExtractProg, i.path)):
                fail.append(i.path)
        if len(fail) > 0:
            self.fm.notify('Fail to extract: {0}'.format(' '.join(fail)), duration=10, bad=True)
        self.fm.redraw_window()

import os
from ranger.core.loader import CommandLoader

class compress(Command):
    def execute(self):
        cwd = self.fm.thisdir
        marked_files = cwd.get_selection()

        if not marked_files:
            return

        def refresh(_):
            cwd = self.fm.get_directory(original_path)
            cwd.load_content()

        original_path = cwd.path
        parts = self.line.split()
        au_flags = parts[1:]

        descr = 'compressing files in: ' + os.path.basename(parts[1])
        obj = CommandLoader(args=['apack'] + au_flags + \
                [os.path.relpath(f.path, cwd.path) for f in marked_files], descr=descr)

        obj.signal_bind('after', refresh)
        self.fm.loader.add(obj)

    def tab(self):
        extension = ['.zip', '.tar.gz', '.rar', '.7z']
        return ['compress ' + os.path.basename(self.fm.thisdir.path) + ext for ext in extension]
" >> ~/.config/ranger/commands.py
git clone https://github.com/alexanderjeurissen/ranger_devicons ~/.config/ranger/plugins/ranger_devicons
echo "default_linemode devicons" >> $HOME/.config/ranger/rc.conf

# 安装 i3;
figlet 'i3'
sudo apt install i3

# 安装一些工具;
figlet 'tools'
sudo apt install net-tools
sudo apt install ssh
sudo apt install htop
sudo apt install tree
sudo apt install curl
sudo apt install unrar
sudo apt install vim-gnome

sudo add-apt-repository ppa:lazygit-team/release
sudo apt-get update
sudo apt-get install lazygit

curl -s https://packagecloud.io/install/repositories/github/git-lfs/script.deb.sh | sudo bash
sudo apt install git-lfs

# 拉取一些工程到本地; 
git clone https://github.com/KylinskyChen/xcCore ~/xcCore  
sudo apt-get install git-lfs
git lfs install
git lfs track "file.suffix"
git add .gitattributes 
git lfs push origin master --all

# 完成;
figlet 'finished'

你可能感兴趣的:(tools)