From 6420b2b102bab214ad0bf1fa0f5e190f02984e82 Mon Sep 17 00:00:00 2001 From: Michael Stapelberg Date: Sun, 25 Sep 2011 18:45:51 +0100 Subject: [PATCH] Introduce the i3-sensible-{pager,editor,terminal} scripts The former two provide fallbacks in case $PAGER or $EDITOR is not set (which might be more common than you think, because they have to be set in ~/.xsession, not in the shell configuration!) while the latter tries to launch a terminal emulator. The scripts are most prominently used in i3-nagbar, which alerts the user when the configuration is broken for some reason. Also, i3-sensible-terminal is used in the default configuration. This commit does not rely on the shell supporting ${PAGER:-less} anymore, which is not the case for 'fish'. --- Makefile | 3 +++ PACKAGE-MAINTAINER | 18 ++++++++++++------ common.mk | 1 - i3-sensible-editor | 14 ++++++++++++++ i3-sensible-pager | 15 +++++++++++++++ i3-sensible-terminal | 15 +++++++++++++++ i3.config | 2 +- i3.config.keycodes | 2 +- src/cfgparse.y | 4 ++-- 9 files changed, 63 insertions(+), 11 deletions(-) create mode 100755 i3-sensible-editor create mode 100755 i3-sensible-pager create mode 100755 i3-sensible-terminal diff --git a/Makefile b/Makefile index 15ccf0e6..bec6b64b 100644 --- a/Makefile +++ b/Makefile @@ -80,6 +80,9 @@ install: all $(INSTALL) -d -m 0755 $(DESTDIR)$(PREFIX)/share/xsessions $(INSTALL) -m 0755 i3 $(DESTDIR)$(PREFIX)/bin/ $(INSTALL) -m 0755 i3-migrate-config-to-v4 $(DESTDIR)$(PREFIX)/bin/ + $(INSTALL) -m 0755 i3-sensible-editor $(DESTDIR)$(PREFIX)/bin/ + $(INSTALL) -m 0755 i3-sensible-pager $(DESTDIR)$(PREFIX)/bin/ + $(INSTALL) -m 0755 i3-sensible-terminal $(DESTDIR)$(PREFIX)/bin/ test -e $(DESTDIR)$(SYSCONFDIR)/i3/config || $(INSTALL) -m 0644 i3.config $(DESTDIR)$(SYSCONFDIR)/i3/config test -e $(DESTDIR)$(SYSCONFDIR)/i3/config.keycodes || $(INSTALL) -m 0644 i3.config.keycodes $(DESTDIR)$(SYSCONFDIR)/i3/config.keycodes $(INSTALL) -m 0644 i3.welcome $(DESTDIR)$(SYSCONFDIR)/i3/welcome diff --git a/PACKAGE-MAINTAINER b/PACKAGE-MAINTAINER index 3d9a8e18..269ce0fd 100644 --- a/PACKAGE-MAINTAINER +++ b/PACKAGE-MAINTAINER @@ -10,15 +10,21 @@ packages for them. Please make sure the manpage for i3 will be properly created and installed in your package. -Also please provide the path to a suitable terminal emulator which is installed -as a dependency of your package (e.g. urxvt). On systems which have a special -commend to launch the best available terminal emulator, please use this one -(e.g. x-terminal-emulator on debian). +Please check the i3-sensible-{editor,pager,terminal} scripts and modify them if +necessary. The former two provide fallbacks in case $PAGER or $EDITOR is not +set (which might be more common than you think, because they have to be set in +~/.xsession, not in the shell configuration!) while the latter tries to launch +a terminal emulator. The scripts are most prominently used in i3-nagbar, which +alerts the user when the configuration is broken for some reason. Also, +i3-sensible-terminal is used in the default configuration. -On debian, this looks like this: +If your distribution has a mechanism to get the preferred terminal, such as the +x-terminal-emulator symlink in Debian, please use it in i3-sensible-terminal. + +On debian, compilation and installing the manpages looks like this: # Compilation - $(MAKE) TERM_EMU=x-terminal-emulator + $(MAKE) $(MAKE) -C man # Installation diff --git a/common.mk b/common.mk index 62eb9958..78033946 100644 --- a/common.mk +++ b/common.mk @@ -12,7 +12,6 @@ ifndef SYSCONFDIR SYSCONFDIR=$(PREFIX)/etc endif endif -TERM_EMU=xterm # The escaping is absurd, but we need to escape for shell, sed, make, define GIT_VERSION:="$(shell git describe --tags --always) ($(shell git log --pretty=format:%cd --date=short -n1), branch $(shell [ -f $(TOPDIR)/.git/HEAD ] && sed 's/ref: refs\/heads\/\(.*\)/\\\\\\"\1\\\\\\"/g' $(TOPDIR)/.git/HEAD || echo 'unknown'))" VERSION:=$(shell git describe --tags --abbrev=0) diff --git a/i3-sensible-editor b/i3-sensible-editor new file mode 100755 index 00000000..dffe00d5 --- /dev/null +++ b/i3-sensible-editor @@ -0,0 +1,14 @@ +#!/bin/sh +# This script tries to exec an editor by trying some known editors if $EDITOR is +# not set. +# +# Distributions/packagers can enhance this script with a +# distribution-specific mechanism to find the preferred pager. +which $VISUAL >/dev/null && exec $VISUAL "$@" +which $EDITOR >/dev/null && exec $EDITOR "$@" + +# Hopefully one of these is installed (no flamewars about preference please!): +which nano >/dev/null && exec nano "$@" +which vim >/dev/null && exec vim "$@" +which vi >/dev/null && exec vi "$@" +which emacs >/dev/null && exec emacs "$@" diff --git a/i3-sensible-pager b/i3-sensible-pager new file mode 100755 index 00000000..5af8d6b4 --- /dev/null +++ b/i3-sensible-pager @@ -0,0 +1,15 @@ +#!/bin/sh +# This script tries to exec a pager by trying some known pagers if $PAGER is +# not set. +# +# Distributions/packagers can enhance this script with a +# distribution-specific mechanism to find the preferred pager. +which $PAGER >/dev/null && exec $PAGER "$@" + +# Hopefully one of these is installed: +which most >/dev/null && exec most "$@" +which less >/dev/null && exec less "$@" +# we don't use 'more' because it will exit if the file is 'too short' + +# If no pager is installed, try an editor +exec i3-sensible-editor "$@" diff --git a/i3-sensible-terminal b/i3-sensible-terminal new file mode 100755 index 00000000..28e60623 --- /dev/null +++ b/i3-sensible-terminal @@ -0,0 +1,15 @@ +#!/bin/sh +# This script tries to exec a terminal emulator by trying some known terminal +# emulators. +# +# Distributions/packagers should enhance this script with a +# distribution-specific mechanism to find the preferred terminal emulator. On +# Debian, there is the x-terminal-emulator symlink for example. +# Please don't touch the first line, though: +which $TERMINAL >/dev/null && exec $TERMINAL "$@" + +# Hopefully one of these is installed: +which xterm >/dev/null && exec xterm "$@" +which urxvt >/dev/null && exec urxvt "$@" +which rxvt >/dev/null && exec rxvt "$@" +which roxterm >/dev/null && exec roxterm "$@" diff --git a/i3.config b/i3.config index 52c4a7e1..7d7fce33 100644 --- a/i3.config +++ b/i3.config @@ -16,7 +16,7 @@ font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1 floating_modifier Mod1 # start a terminal -bindsym Mod1+Return exec urxvt +bindsym Mod1+Return exec i3-sensible-terminal # kill focused window bindsym Mod1+Shift+q kill diff --git a/i3.config.keycodes b/i3.config.keycodes index 17e7483b..0f1112db 100644 --- a/i3.config.keycodes +++ b/i3.config.keycodes @@ -17,7 +17,7 @@ font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1 floating_modifier $mod # start a terminal -bindcode $mod+36 exec urxvt +bindcode $mod+36 exec i3-sensible-terminal # kill focused window bindcode $mod+Shift+24 kill diff --git a/src/cfgparse.y b/src/cfgparse.y index 12a60f4d..9a417f2a 100644 --- a/src/cfgparse.y +++ b/src/cfgparse.y @@ -276,9 +276,9 @@ static void start_configerror_nagbar(const char *config_path) { if (configerror_pid == 0) { char *editaction, *pageraction; - if (asprintf(&editaction, TERM_EMU " -e sh -c \"${EDITOR:-vi} \"%s\" && i3-msg reload\"", config_path) == -1) + if (asprintf(&editaction, "i3-sensible-terminal -e sh -c \"i3-sensible-editor \\\"%s\\\" && i3-msg reload\"", config_path) == -1) exit(1); - if (asprintf(&pageraction, TERM_EMU " -e sh -c \"${PAGER:-less} \"%s\"\"", errorfilename) == -1) + if (asprintf(&pageraction, "i3-sensible-terminal -e i3-sensible-pager \"%s\"", errorfilename) == -1) exit(1); char *argv[] = { NULL, /* will be replaced by the executable path */ -- 2.39.5