summaryrefslogtreecommitdiff
path: root/extra/source/bash-completion/patches/0005-tar-Detect-GNU-other-from-version-only-once-per-sess.patch
blob: 3e5e06e0712824017c3d3891f73191276c56b338 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
From 88c671a2c74bfde3bc2ec7c6f74133ac613c61da Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Ville=20Skytt=C3=A4?= <ville.skytta@iki.fi>
Date: Wed, 16 Mar 2016 12:44:40 +0200
Subject: [PATCH 5/5] tar: Detect GNU/other from --version only once per
 session

---
 completions/tar | 15 ++++++++++++---
 1 file changed, 12 insertions(+), 3 deletions(-)

diff --git a/completions/tar b/completions/tar
index 9c44dc7..7b3a486 100644
--- a/completions/tar
+++ b/completions/tar
@@ -696,16 +696,25 @@ _posix_tar()
 
 _tar()
 {
-    local cmd=${COMP_WORDS[0]} line
+    local cmd=${COMP_WORDS[0]} func line
     read line <<<"$($cmd --version)"
     case "$line" in
     *GNU*)
-        _gtar "$@"
+        func=_gtar
         ;;
     *)
-        _posix_tar "$@"
+        func=_posix_tar
         ;;
     esac
+    $func "$@"
+
+    # Install real completion for subsequent completions
+    if [ -n "${COMP_TAR_INTERNAL_PATHS:-}" ]; then
+        complete -F $func -o dirnames tar
+    else
+        complete -F $func tar
+    fi
+    unset -f _tar
 }
 
 
-- 
2.7.2