Created
October 16, 2012 14:12
-
-
Save bentayloruk/3899506 to your computer and use it in GitHub Desktop.
Reset Pathogen Bundles from Github and Vim.org
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(* | |
Reset Pathogen Bundles from Github and Vim.org | |
__IMPORTANT__ | |
* THIS SCRIPT WILL DELETE ALL BUNDLES IN YOUR PATHOGEN BUNDLE FOLDER. | |
* THIS SCRIPT MAY BE X-PLAT BUT I'VE NOT TESTED IT, SO I DOUBT IT IS. | |
* THERE IS NOT MUCH IN THE WAY OF ERROR RECOVER IN THIS SCRIPT. | |
__Installation__ | |
1. Install Pathogen https://github.com/tpope/vim-pathogen | |
2. Copy this script into your vimfiles (or .vim) directory. | |
3. Edit gitBundles to include the Pathogen compliant git bundles you want. | |
4. Edit vimOrgScripts to include the vim.org scripts you want. | |
5. Run it!! | |
F# script inspired by http://tammersaleh.com/posts/the-modern-vim-config-with-pathogen | |
*) | |
(* Do your config here *) | |
// Config your git sourced bundles. | |
let gitBundles = [ | |
"git://github.com/scrooloose/nerdtree.git" | |
"git://github.com/tpope/vim-git.git" | |
"git://github.com/tpope/vim-markdown.git" | |
"git://github.com/nanotech/jellybeans.vim.git" | |
"git://github.com/DrTom/fsharp-vim.git" | |
"https://github.com/tpope/vim-surround" | |
"https://github.com/tpope/vim-unimpaired" | |
"https://github.com/tpope/vim-ragtag" | |
] | |
// Config your Vim.org scripts. | |
let vimOrgScripts = [ | |
"IndexedSearch", "7062", "plugin" | |
"jquery", "12107", "syntax" | |
] | |
//No config below me... | |
open System | |
open System.IO | |
open System.Diagnostics | |
///Get x64 and x86 Prog File root paths. | |
let gitPath = | |
let gitProgFileRelativePath = Path.Combine("Git", "bin", "git.exe") | |
[ Environment.SpecialFolder.ProgramFiles; Environment.SpecialFolder.ProgramFilesX86 ] | |
|> List.map (fun sf -> Environment.GetFolderPath(sf)) | |
|> Seq.tryPick (fun path -> | |
let maybeFilePath = Path.Combine(path, gitProgFileRelativePath) | |
printfn "Looking in %s" maybeFilePath | |
match File.Exists(maybeFilePath) with | true -> Some(maybeFilePath) | false -> None | |
) | |
//Bail out if no Git. | |
if gitPath.IsNone then failwith "Unable to locate Git.exe in any Program Files folder." | |
///Directly exec git | |
let execGitWith arguments workingDir = | |
printfn "Git args %s and workingdir %s" arguments workingDir | |
let gitInfo = new ProcessStartInfo() | |
gitInfo.CreateNoWindow <- true | |
gitInfo.FileName <- gitPath.Value | |
gitInfo.Arguments <- arguments | |
gitInfo.WorkingDirectory <- workingDir | |
gitInfo.UseShellExecute <- false | |
let gitProcess = new Process() | |
gitProcess.StartInfo <- gitInfo; | |
let _ = gitProcess.Start() | |
gitProcess.WaitForExit() | |
gitProcess.Close() | |
let deleteDirRec path = | |
//Here because Windows Directory.Delete does not handle read only files. | |
let dir = DirectoryInfo(path, Attributes = FileAttributes.Normal) | |
let fileSystemInfos = dir.GetFileSystemInfos("*", SearchOption.AllDirectories) | |
fileSystemInfos |> Seq.iter (fun info -> info.Attributes <- FileAttributes.Normal) | |
dir.Delete(true); | |
(* GET THE GIT BUNDLES AND THEN REMOVE THE GIT FOLDER *) | |
let bundlesDir = Path.Combine(__SOURCE_DIRECTORY__, "bundle") | |
printfn "Deleting all directories in %s" bundlesDir | |
Directory.GetDirectories(bundlesDir, "*") | |
|> Seq.iter (fun dir -> | |
printfn "Deleting %s" dir | |
deleteDirRec dir | |
) | |
gitBundles | |
|> Seq.iter (fun url -> | |
let dir = | |
url.Split('/') | |
|> fun a -> a.[a.Length-1] | |
|> fun repoFn-> repoFn.Replace(".git","") | |
|> fun dir -> Path.Combine(bundlesDir, dir) | |
Directory.CreateDirectory(dir) |> ignore | |
printfn "Unpacking %s into %s" url dir | |
execGitWith (sprintf "clone %s" url) bundlesDir | |
let gitRepos = Path.Combine(bundlesDir, dir, ".git") | |
printfn "Deleting git dir %s" gitRepos | |
deleteDirRec gitRepos | |
) | |
vimOrgScripts | |
|> Seq.iter (fun (script_name, script_id, script_type) -> | |
let dir = Path.Combine(bundlesDir, script_name, script_type) | |
let _ = Directory.CreateDirectory(dir) | |
printfn "Downloading %s" script_name | |
use wc = new System.Net.WebClient() | |
let script = wc.DownloadString(sprintf "http://www.vim.org/scripts/download_script.php?src_id=%s" script_id) | |
let filePath = Path.Combine(dir, sprintf "%s.vim" script_name) | |
File.WriteAllText(filePath, script) | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment