Skip to content

Instantly share code, notes, and snippets.

@TylerLeonhardt
Last active August 1, 2019 17:37
Show Gist options
  • Save TylerLeonhardt/fe67fd8c32dadff07b003e85efab3944 to your computer and use it in GitHub Desktop.
Save TylerLeonhardt/fe67fd8c32dadff07b003e85efab3944 to your computer and use it in GitHub Desktop.
Helps install vim on Linux without needing sudo (this will build and install vim and its dependency ncurses)
param(
# Version of ncurses to download
[Parameter()]
[string]
$NCursesVersion = '6.1'
)
# Create the directory that we'll add to the path.
if (!(Test-Path ~/usr/local)) {
New-Item ~/usr/local -ItemType Directory -Force | Out-Null
}
# Create the directory where we will store ncurses & vim source code
# and navigate to that location.
if (!(Test-Path ~/.vimtools)) {
New-Item ~/.vimtools -ItemType Directory -Force | Out-Null
}
Push-Location ~/.vimtools
# Grab ncurses needed to build vim and extract it.
$ncursesFolderName = "ncurses-$NCursesVersion"
# If we have ncurses already, we don't need to get it again.
if(!(Test-Path $ncursesFolderName)) {
Write-Warning "ncurses not detected. Fetching and installing ncurses."
$ncursesZipName = "$ncursesFolderName.tar.gz"
Invoke-RestMethod -Uri "http://ftp.gnu.org/pub/gnu/ncurses/$ncursesZipName" -OutFile $ncursesZipName
tar -xzvf $ncursesZipName
# Navigate into the ncurses directory and build the project.
Push-Location $ncursesFolderName
Write-Warning "Building ncurses..."
./configure --prefix=$HOME/usr/local
make
make install
Pop-Location
} else {
Write-Warning "ncurses already installed. Skipping."
}
# Clone the vim source code navigate into the source and build the project.
if (Test-Path vim) {
Write-Warning "Vim source detected. Pulling instead of cloning."
Push-Location vim
git pull
Pop-Location
} else {
Write-Warning "Vim source not detected. Cloning vim..."
git clone https://github.com/vim/vim.git
}
Push-Location vim/src
Write-Warning "Building Vim..."
$env:LDFLAGS = "-L$HOME/usr/local/lib"
./configure --prefix=$HOME/usr/local
make
make install
Pop-Location
Pop-Location
# update PATH so vim is exposed.
$env:PATH = "$HOME/usr/local/bin:$env:PATH"
Write-Host @'
.
##############..... ##############
##############......##############
##########..........##########
##########........##########
##########.......##########
##########.....##########..
##########....##########.....
..##########..##########.........
....##########.#########.............
..################JJJ............
################.............
##############.JJJ.JJJJJJJJJJ
############...JJ...JJ..JJ JJ
##########....JJ...JJ..JJ JJ
########......JJJ..JJJ JJJ JJJ
###### .........
.....
.
All done!
You should add the following line to your profile so that the path win your newly built vim is available:
$env:PATH = "$HOME/usr/local/bin:$env:PATH"
'@
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment