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,28 +97,27 @@ proc cmd(cmd: string): string =
97 except: 97 except:
98 result = nil 98 result = nil
99 99
100 -# Find git root dir or nil 100 +# Various git commands
101 proc gitRoot(): string = 101 proc gitRoot(): string =
102 cmd("git rev-parse --show-toplevel") 102 cmd("git rev-parse --show-toplevel")
103 -  
104 -# Git config  
105 proc gitConfigSet(key, val: string) = 103 proc gitConfigSet(key, val: string) =
106 discard cmd("git config " & $key & " " & $val) 104 discard cmd("git config " & $key & " " & $val)
107 - 105 +proc gitConfigUnset(key: string) =
  106 + discard cmd("git config --unset " & $key)
108 proc gitConfigGet(key: string): string = 107 proc gitConfigGet(key: string): string =
109 cmd("git config --get " & $key) 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 # Ensure the filter is set 110 # Ensure the filter is set
118 proc ensureBlimpFilter() = 111 proc ensureBlimpFilter() =
119 if gitConfigGet("filter.blimp.clean") != "": 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 # Simple expansion of %home%, %cwd% and %gitroot% 122 # Simple expansion of %home%, %cwd% and %gitroot%
124 proc expandDirs(templ: string): string = 123 proc expandDirs(templ: string): string =
@@ -378,25 +377,14 @@ proc dumpConfig() = @@ -378,25 +377,14 @@ proc dumpConfig() =
378 echo "\tblimpVersion: " & $blimpVersion 377 echo "\tblimpVersion: " & $blimpVersion
379 echo "\n" 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 let synopsis = """ 380 let synopsis = """
394 blimp [options] <command> <filenames...> 381 blimp [options] <command> <filenames...>
395 -h,--help Show this 382 -h,--help Show this
396 --version Show version of blimp 383 --version Show version of blimp
397 -v,--verbose Verbosity, only works without -s 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 --all Operate on all deflated files in clone 388 --all Operate on all deflated files in clone
401 -f,--filter Operate on all files matching blimp filter 389 -f,--filter Operate on all files matching blimp filter
402 -a,--area (default remote) The area to use for remote up/downloads 390 -a,--area (default remote) The area to use for remote up/downloads
@@ -507,7 +495,7 @@ area = args[&quot;area&quot;].asString @@ -507,7 +495,7 @@ area = args[&quot;area&quot;].asString
507 if stdio: 495 if stdio:
508 verbose = false 496 verbose = false
509 try: 497 try:
510 - stdinContent = readAllX(stdin) 498 + stdinContent = readAll(stdin)
511 close(stdin) 499 close(stdin)
512 except: 500 except:
513 quit("Failed reading stdin", 1) 501 quit("Failed reading stdin", 1)
@@ -569,6 +557,10 @@ if command != &quot;&quot;: @@ -569,6 +557,10 @@ if command != &quot;&quot;:
569 ensureBlimpFilter() 557 ensureBlimpFilter()
570 echo("Installed blimp filter") 558 echo("Installed blimp filter")
571 quit(0) 559 quit(0)
  560 + elif command == "deinit":
  561 + removeBlimpFilter()
  562 + echo("Removed blimp filter")
  563 + quit(0)
572 elif command == "d" or command == "deflate": 564 elif command == "d" or command == "deflate":
573 for fn in filenames: 565 for fn in filenames:
574 deflate(fn) 566 deflate(fn)