Skip to content

Instantly share code, notes, and snippets.

@bentayloruk
Created October 16, 2012 14:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bentayloruk/3899506 to your computer and use it in GitHub Desktop.
Save bentayloruk/3899506 to your computer and use it in GitHub Desktop.
Reset Pathogen Bundles from Github and Vim.org
(*
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