Commit 543fb24855afb752934dfc53043a062f6b170ac7

Authored by Göran Krampe
1 parent 58f865a2

Added deinit to remove filter

Showing 1 changed file with 17 additions and 25 deletions
blimp.nim
... ... @@ -97,28 +97,27 @@ proc cmd(cmd: string): string =
97 97 except:
98 98 result = nil
99 99  
100   -# Find git root dir or nil
  100 +# Various git commands
101 101 proc gitRoot(): string =
102 102 cmd("git rev-parse --show-toplevel")
103   -
104   -# Git config
105 103 proc gitConfigSet(key, val: string) =
106 104 discard cmd("git config " & $key & " " & $val)
107   -
  105 +proc gitConfigUnset(key: string) =
  106 + discard cmd("git config --unset " & $key)
108 107 proc gitConfigGet(key: string): string =
109 108 cmd("git config --get " & $key)
110 109  
111   -# Set blimp filter
112   -proc setBlimpFilter() =
113   - gitConfigSet("filter.blimp.clean", "\"blimp -s d %f\"")
114   - gitConfigSet("filter.blimp.smudge", "\"blimp -s i %f\"")
115   -
116   -
117 110 # Ensure the filter is set
118 111 proc ensureBlimpFilter() =
119 112 if gitConfigGet("filter.blimp.clean") != "":
120   - setBlimpFilter()
  113 + gitConfigSet("filter.blimp.clean", "\"blimp -s d %f\"")
  114 + gitConfigSet("filter.blimp.smudge", "\"blimp -s i %f\"")
121 115  
  116 +# Ensure the filter is set
  117 +proc removeBlimpFilter() =
  118 + if gitConfigGet("filter.blimp.clean") != "":
  119 + gitConfigUnset("filter.blimp.clean")
  120 + gitConfigUnset("filter.blimp.smudge")
122 121  
123 122 # Simple expansion of %home%, %cwd% and %gitroot%
124 123 proc expandDirs(templ: string): string =
... ... @@ -378,25 +377,14 @@ proc dumpConfig() =
378 377 echo "\tblimpVersion: " & $blimpVersion
379 378 echo "\n"
380 379  
381   -proc readAllX(file: File): string =
382   - result = ""
383   - var buffer = newString(4096)
384   - while true:
385   - var read = readBuffer(file, addr(buffer[0]), 4096)
386   - if read == 4096:
387   - result.add(buffer)
388   - else:
389   - buffer.setLen(read)
390   - result.add(buffer)
391   - break
392   -
393 380 let synopsis = """
394 381 blimp [options] <command> <filenames...>
395 382 -h,--help Show this
396 383 --version Show version of blimp
397 384 -v,--verbose Verbosity, only works without -s
398 385 ----------
399   - <command> (string) (d)eflate, (i)nflate, init, remove, push, upload, download
  386 + <command> (string) (d)eflate, (i)nflate, init, deinit,
  387 + remove, push, upload, download
400 388 --all Operate on all deflated files in clone
401 389 -f,--filter Operate on all files matching blimp filter
402 390 -a,--area (default remote) The area to use for remote up/downloads
... ... @@ -507,7 +495,7 @@ area = args[&quot;area&quot;].asString
507 495 if stdio:
508 496 verbose = false
509 497 try:
510   - stdinContent = readAllX(stdin)
  498 + stdinContent = readAll(stdin)
511 499 close(stdin)
512 500 except:
513 501 quit("Failed reading stdin", 1)
... ... @@ -569,6 +557,10 @@ if command != &quot;&quot;:
569 557 ensureBlimpFilter()
570 558 echo("Installed blimp filter")
571 559 quit(0)
  560 + elif command == "deinit":
  561 + removeBlimpFilter()
  562 + echo("Removed blimp filter")
  563 + quit(0)
572 564 elif command == "d" or command == "deflate":
573 565 for fn in filenames:
574 566 deflate(fn)
... ...