salimma / rpms / fish

Forked from rpms/fish 3 days ago
Clone

Blame 0001-Add-functions-and-configuration-snippets-hierarchy.patch

Andy Lutomirski 30fc8a
[Backport by amluto: use basename instead of string replace]
Andy Lutomirski 30fc8a
Andy Lutomirski 30fc8a
From c1b384e5d3f2f46e7d7a1b41e31c7aadc1d9ce28 Mon Sep 17 00:00:00 2001
Andy Lutomirski 30fc8a
Message-Id: <c1b384e5d3f2f46e7d7a1b41e31c7aadc1d9ce28.1456513347.git.luto@kernel.org>
Andy Lutomirski 30fc8a
From: Fabian Homborg <FHomborg@gmail.com>
Andy Lutomirski 30fc8a
Date: Tue, 20 Oct 2015 23:21:57 +0200
Andy Lutomirski 30fc8a
Subject: [PATCH] Add functions and configuration snippets hierarchy
Andy Lutomirski 30fc8a
Andy Lutomirski 30fc8a
This allows "vendors" (i.e. third-party upstreams interested in
Andy Lutomirski 30fc8a
supporting fish) to add auto-loaded functions and eager-loaded
Andy Lutomirski 30fc8a
configuration "snippets", while still allowing both the user and the administrator to
Andy Lutomirski 30fc8a
fully override all of that.
Andy Lutomirski 30fc8a
Andy Lutomirski 30fc8a
This has been inspired by systemd's configuration hierarchy, and implements a similar scheme
Andy Lutomirski 30fc8a
whereby files with the same name in higher-ranking directories override files in lower-ranking ones.
Andy Lutomirski 30fc8a
Andy Lutomirski 30fc8a
Fixes #1956
Andy Lutomirski 30fc8a
---
Andy Lutomirski 30fc8a
 Makefile.in          |  3 +++
Andy Lutomirski 30fc8a
 doc_src/index.hdr.in |  1 +
Andy Lutomirski 30fc8a
 fish.pc.in           |  2 ++
Andy Lutomirski 30fc8a
 share/config.fish    | 14 +++++++++++++-
Andy Lutomirski 30fc8a
 4 files changed, 19 insertions(+), 1 deletion(-)
Andy Lutomirski 30fc8a
Andy Lutomirski 30fc8a
diff --git a/Makefile.in b/Makefile.in
Andy Lutomirski 30fc8a
index 88155b2d58fd..056a3d814457 100644
Andy Lutomirski 30fc8a
--- a/Makefile.in
Andy Lutomirski 30fc8a
+++ b/Makefile.in
Andy Lutomirski 30fc8a
@@ -660,9 +660,12 @@ install-force: all install-translations
Andy Lutomirski 30fc8a
 		true ;\
Andy Lutomirski 30fc8a
 	done;
Andy Lutomirski 30fc8a
 	$(INSTALL) -m 755 -d $(DESTDIR)$(sysconfdir)/fish
Andy Lutomirski 30fc8a
+	$(INSTALL) -m 755 -d $(DESTDIR)$(sysconfdir)/fish/conf.d
Andy Lutomirski 30fc8a
 	$(INSTALL) -m 755 -d $(DESTDIR)$(datadir)/fish
Andy Lutomirski 30fc8a
 	$(INSTALL) -m 755 -d $(DESTDIR)$(datadir)/fish/completions
Andy Lutomirski 30fc8a
 	$(INSTALL) -m 755 -d $(DESTDIR)$(datadir)/fish/vendor_completions.d
Andy Lutomirski 30fc8a
+	$(INSTALL) -m 755 -d $(DESTDIR)$(datadir)/fish/vendor_functions.d
Andy Lutomirski 30fc8a
+	$(INSTALL) -m 755 -d $(DESTDIR)$(datadir)/fish/vendor_conf.d
Andy Lutomirski 30fc8a
 	$(INSTALL) -m 755 -d $(DESTDIR)$(datadir)/fish/functions
Andy Lutomirski 30fc8a
 	$(INSTALL) -m 755 -d $(DESTDIR)$(datadir)/fish/man/man1
Andy Lutomirski 30fc8a
 	$(INSTALL) -m 755 -d $(DESTDIR)$(datadir)/fish/tools
Andy Lutomirski 30fc8a
diff --git a/doc_src/index.hdr.in b/doc_src/index.hdr.in
Andy Lutomirski 30fc8a
index 9531876b5aca..a0f7ec0a2001 100644
Andy Lutomirski 30fc8a
--- a/doc_src/index.hdr.in
Andy Lutomirski 30fc8a
+++ b/doc_src/index.hdr.in
Andy Lutomirski 30fc8a
@@ -1088,6 +1088,7 @@ function on_exit --on-process %self
Andy Lutomirski 30fc8a
 end
Andy Lutomirski 30fc8a
 \endfish
Andy Lutomirski 30fc8a
 
Andy Lutomirski 30fc8a
+Right after reading /usr/share/fish/config.fish and before reading /etc/fish/config.fish, fish will also read files in ~/.config/fish/conf.d/, /etc/fish/conf.d and /usr/share/fish/vendor_conf.d (the exact values depend on $XDG_CONFIG_HOME, $__fish_sysconfdir and $__fish_datadir). If there are files with the same name in two or all of these, fish will only attempt to read the first (skipping all files with that name if it is unreadable). ~/.config takes precedence over /etc/ which takes precedence over /usr. The path to the latter can also be gotten via `pkg-config` as "confdir", and is meant for third-party applications to integrate with fish.
Andy Lutomirski 30fc8a
 
Andy Lutomirski 30fc8a
 \section other Other features
Andy Lutomirski 30fc8a
 
Andy Lutomirski 30fc8a
diff --git a/fish.pc.in b/fish.pc.in
Andy Lutomirski 30fc8a
index cae82246b808..c8fabd7e8fbf 100644
Andy Lutomirski 30fc8a
--- a/fish.pc.in
Andy Lutomirski 30fc8a
+++ b/fish.pc.in
Andy Lutomirski 30fc8a
@@ -1,6 +1,8 @@
Andy Lutomirski 30fc8a
 prefix=@prefix@
Andy Lutomirski 30fc8a
 datadir=@datadir@
Andy Lutomirski 30fc8a
 completionsdir=${datadir}/fish/vendor_completions.d
Andy Lutomirski 30fc8a
+functionsdir=${datadir}/fish/vendor_functions.d
Andy Lutomirski 30fc8a
+confdir=${datadir}/fish/vendor_conf.d
Andy Lutomirski 30fc8a
 
Andy Lutomirski 30fc8a
 Name: fish
Andy Lutomirski 30fc8a
 Description: fish, the friendly interactive shell
Andy Lutomirski 30fc8a
diff --git a/share/config.fish b/share/config.fish
Andy Lutomirski 30fc8a
index b1d404eecdac..40000740971b 100644
Andy Lutomirski 30fc8a
--- a/share/config.fish
Andy Lutomirski 30fc8a
+++ b/share/config.fish
Andy Lutomirski 30fc8a
@@ -49,7 +49,7 @@ end
Andy Lutomirski 30fc8a
 # default functions/completions are included in the respective path.
Andy Lutomirski 30fc8a
 
Andy Lutomirski 30fc8a
 if not set -q fish_function_path
Andy Lutomirski 30fc8a
-	set fish_function_path $configdir/fish/functions    $__fish_sysconfdir/functions    $__fish_datadir/functions
Andy Lutomirski 30fc8a
+	set fish_function_path $configdir/fish/functions    $__fish_sysconfdir/functions $__fish_datadir/vendor_functions.d   $__fish_datadir/functions
Andy Lutomirski 30fc8a
 end
Andy Lutomirski 30fc8a
 
Andy Lutomirski 30fc8a
 if not contains $__fish_datadir/functions $fish_function_path
Andy Lutomirski 30fc8a
@@ -151,3 +151,15 @@ function . --description 'Evaluate contents of file (deprecated, see "source")'
Andy Lutomirski 30fc8a
 		source $argv
Andy Lutomirski 30fc8a
 	end
Andy Lutomirski 30fc8a
 end
Andy Lutomirski 30fc8a
+
Andy Lutomirski 30fc8a
+# As last part of initialization, source the conf directories
Andy Lutomirski 30fc8a
+# Implement precedence (User > Admin > Vendors > Fish) by basically doing "basename"
Andy Lutomirski 30fc8a
+set -l sourcelist
Andy Lutomirski 30fc8a
+for file in $configdir/fish/conf.d/* $__fish_sysconfdir/conf.d/* $__fish_datadir/vendor_conf.d/*
Andy Lutomirski 30fc8a
+	set -l basename (basename -- $file)
Andy Lutomirski 30fc8a
+	contains -- $basename $sourcelist; and continue
Andy Lutomirski 30fc8a
+	set sourcelist $sourcelist $basename
Andy Lutomirski 30fc8a
+	# Also skip non-files or unreadable files
Andy Lutomirski 30fc8a
+	# This allows one to use e.g. symlinks to /dev/null to "mask" something (like in systemd)
Andy Lutomirski 30fc8a
+	[ -f $file -a -r $file ]; and source $file
Andy Lutomirski 30fc8a
+end
Andy Lutomirski 30fc8a
-- 
Andy Lutomirski 30fc8a
2.5.0
Andy Lutomirski 30fc8a