+# Copyright (C) 2011-2014 Simon Ruderich
+#
+# This file is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This file is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this file. If not, see <http://www.gnu.org/licenses/>.
+
+
+# Warn when creating global variables from inside a function. Needs to be set
+# before declaring a function.
+setopt warn_create_global
+
+
+# HELPER FUNCTIONS
+
+# Return the name of the program which is called in the foreground with `fg`.
+# $1 is the name of the program (optional). If it's not 'fg' or 'fg *' it's
+# returned unchanged.
+zshrc_resolve_fg_to_resumed_job_name() {
+ # $REPLY is used by convention for scalars ($reply for arrays) to return
+ # values from functions. unset it here to prevent problems when REPLY is
+ # bound to an integer or similar. Thanks to Mikachu in #zsh on Freenode
+ # (2012-09-27 17:14 CEST) for this hint.
+ unset REPLY
+
+ # Replace fg with the resumed job name.
+ if [[ $1 == fg ]]; then
+ REPLY=${jobtexts[%+]}
+ elif [[ $1 == fg\ * ]]; then
+ REPLY=${jobtexts[${1#fg }]}
+ # Normal program, return as is.
+ else
+ REPLY=$1
+ fi
+}