Released as 20240522 ('Tbilisi')
[parallel.git] / src / env_parallel
blob0f05192f09d103e36dafd83144b767d6343c8824
1 #!/usr/bin/env bash
3 # Copyright (C) 2016-2024 Ole Tange, http://ole.tange.dk and Free
4 # Software Foundation, Inc.
6 # This program is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 3 of the License, or
9 # (at your option) any later version.
11 # This program is distributed in the hope that it will be useful, but
12 # WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 # General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program; if not, see <http://www.gnu.org/licenses/>
18 # or write to the Free Software Foundation, Inc., 51 Franklin St,
19 # Fifth Floor, Boston, MA 02110-1301 USA
21 # SPDX-FileCopyrightText: 2021-2024 Ole Tange, http://ole.tange.dk and Free Software and Foundation, Inc.
22 # SPDX-License-Identifier: GPL-3.0-or-later
24 grepq() {
25 # grep -q for systems without -q
26 grep >/dev/null 2>/dev/null "$@"
29 installer() {
30 source="$1"
31 script="$2"
32 into="$3"
33 if grepq $script "$into"; then
34 true already installed
35 else
36 echo $source \`which $script\` >> "$into"
40 while test $# -gt 0; do
41 key="$1"
43 case $key in
44 -i|--install)
45 installer . env_parallel.bash "$HOME"/.bashrc
46 installer . env_parallel.sh "$HOME"/.shrc
47 installer . env_parallel.zsh "$HOME"/.zshenv
48 installer source env_parallel.ksh "$HOME"/.kshrc
49 installer source env_parallel.mksh "$HOME"/.mkshrc
50 echo $SHELL | grepq /pdksh &&
51 installer . env_parallel.pdksh "$HOME"/.profile
52 echo $SHELL | grepq /ash &&
53 installer . env_parallel.ash "$HOME"/.profile
54 echo $SHELL | grepq /dash &&
55 installer . env_parallel.dash "$HOME"/.profile
56 installer source env_parallel.csh "$HOME"/.cshrc
57 installer source env_parallel.tcsh "$HOME"/.tcshrc
58 mkdir -p "$HOME"/.config/fish
59 grepq env_parallel.fish "$HOME"/.config/fish/config.fish ||
60 echo '. (which env_parallel.fish)' >> "$HOME"/.config/fish/config.fish
61 echo 'Installed env_parallel in:'
62 echo " " "$HOME"/.bashrc
63 echo " " "$HOME"/.shrc
64 echo " " "$HOME"/.zshenv
65 echo " " "$HOME"/.config/fish/config.fish
66 echo " " "$HOME"/.kshrc
67 echo " " "$HOME"/.mkshrc
68 echo " " "$HOME"/.profile
69 echo " " "$HOME"/.cshrc
70 echo " " "$HOME"/.tcshrc
71 exit
74 echo "Unknown option: $key"
76 esac
77 shift # past argument or value
78 done
81 cat <<'_EOS'
82 You have called the dummy script "env_parallel".
84 env_parallel only works if it is a function.
86 You need to do this and restart your shell:
88 bash: Put this in $HOME/.bashrc: . env_parallel.bash
89 E.g. by doing: echo '. env_parallel.bash' >> $HOME/.bashrc
90 Supports: variables, aliases, functions, arrays
92 fish: Put this in $HOME/.config/fish/config.fish: . (which env_parallel.fish)
93 E.g. by doing:
94 echo '. (which env_parallel.fish)' >> $HOME/.config/fish/config.fish
95 Supports: variables, aliases, functions, arrays
97 ksh: Put this in $HOME/.kshrc: source env_parallel.ksh
98 E.g. by doing: echo 'source env_parallel.ksh' >> $HOME/.kshrc
99 Supports: variables, aliases, functions, arrays
101 mksh: Put this in $HOME/.mkshrc: source env_parallel.mksh
102 E.g. by doing: echo 'source env_parallel.mksh' >> $HOME/.mkshrc
103 Supports: variables, aliases, functions, arrays
105 pdksh: Put this in $HOME/.profile: source env_parallel.pdksh
106 E.g. by doing: echo '. env_parallel.pdksh' >> $HOME/.profile
107 Supports: variables, aliases, functions, arrays
109 zsh: Put this in $HOME/.zshrc: . env_parallel.zsh
110 E.g. by doing: echo '. env_parallel.zsh' >> $HOME/.zshenv
111 Supports: variables, functions, arrays
113 ash: Put this in $HOME/.profile: . env_parallel.ash
114 E.g. by doing: echo '. env_parallel.ash' >> $HOME/.profile
115 Supports: variables, aliases
117 dash: Put this in $HOME/.profile: . env_parallel.dash
118 E.g. by doing: echo '. env_parallel.dash' >> $HOME/.profile
119 Supports: variables, aliases
121 csh: Put this in $HOME/.cshrc: source `which env_parallel.csh`
122 E.g. by doing: echo 'source `which env_parallel.csh`' >> $HOME/.cshrc
123 Supports: variables, aliases, arrays with no special chars
125 tcsh: Put this in $HOME/.tcshrc: source `which env_parallel.tcsh`
126 E.g. by doing: echo 'source `which env_parallel.tcsh`' >> $HOME/.tcshrc
127 Supports: variables, aliases, arrays with no special chars
129 To install in all shells run:
131 env_parallel --install
133 In a script you need to run this before using env_parallel:
135 bash: . env_parallel.bash
136 ksh: source env_parallel.ksh
137 mksh: source env_parallel.mksh
138 pdksh: source env_parallel.pdksh
139 zsh: . env_parallel.zsh
140 ash: . env_parallel.ash
141 dash: . env_parallel.dash
143 For details: see man env_parallel
145 _EOS