diff --git a/blimp.nim b/blimp.nim index 858bf52..9106a25 100644 --- a/blimp.nim +++ b/blimp.nim @@ -97,28 +97,27 @@ proc cmd(cmd: string): string = except: result = nil -# Find git root dir or nil +# Various git commands proc gitRoot(): string = cmd("git rev-parse --show-toplevel") - -# Git config proc gitConfigSet(key, val: string) = discard cmd("git config " & $key & " " & $val) - +proc gitConfigUnset(key: string) = + discard cmd("git config --unset " & $key) proc gitConfigGet(key: string): string = cmd("git config --get " & $key) -# Set blimp filter -proc setBlimpFilter() = - gitConfigSet("filter.blimp.clean", "\"blimp -s d %f\"") - gitConfigSet("filter.blimp.smudge", "\"blimp -s i %f\"") - - # Ensure the filter is set proc ensureBlimpFilter() = if gitConfigGet("filter.blimp.clean") != "": - setBlimpFilter() + gitConfigSet("filter.blimp.clean", "\"blimp -s d %f\"") + gitConfigSet("filter.blimp.smudge", "\"blimp -s i %f\"") +# Ensure the filter is set +proc removeBlimpFilter() = + if gitConfigGet("filter.blimp.clean") != "": + gitConfigUnset("filter.blimp.clean") + gitConfigUnset("filter.blimp.smudge") # Simple expansion of %home%, %cwd% and %gitroot% proc expandDirs(templ: string): string = @@ -378,25 +377,14 @@ proc dumpConfig() = echo "\tblimpVersion: " & $blimpVersion echo "\n" -proc readAllX(file: File): string = - result = "" - var buffer = newString(4096) - while true: - var read = readBuffer(file, addr(buffer[0]), 4096) - if read == 4096: - result.add(buffer) - else: - buffer.setLen(read) - result.add(buffer) - break - let synopsis = """ blimp [options] -h,--help Show this --version Show version of blimp -v,--verbose Verbosity, only works without -s ---------- - (string) (d)eflate, (i)nflate, init, remove, push, upload, download + (string) (d)eflate, (i)nflate, init, deinit, + remove, push, upload, download --all Operate on all deflated files in clone -f,--filter Operate on all files matching blimp filter -a,--area (default remote) The area to use for remote up/downloads @@ -507,7 +495,7 @@ area = args["area"].asString if stdio: verbose = false try: - stdinContent = readAllX(stdin) + stdinContent = readAll(stdin) close(stdin) except: quit("Failed reading stdin", 1) @@ -569,6 +557,10 @@ if command != "": ensureBlimpFilter() echo("Installed blimp filter") quit(0) + elif command == "deinit": + removeBlimpFilter() + echo("Removed blimp filter") + quit(0) elif command == "d" or command == "deflate": for fn in filenames: deflate(fn)