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 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516
|
#!/usr/local/bin/zsh
#
# NAME:
# reporter
#
# SYNOPSIS:
# reporter [all | aliases | bindings | completion | functions |
# limits | options | variables | zstyles]
#
# DESCRIPTION:
# "reporter" prints your current environment variables, shell
# variables, limits, completion settings, and option settings to
# stdout in the form of a script.
#
# If you run into a zsh bug, someone can source the output script to
# recreate most of the environment under which you were working.
#
# IMPORTANT: "source" this script, don't try to run it directly.
# Otherwise it won't report the settings for your
# current shell session.
#
# OPTIONS:
# All command-line options can be abbreviated.
#
# "aliases" prints only aliases.
# "bindings" prints only "bindkey" commands.
# "completion" prints only "compctl" commands.
# "functions" prints "autoload" commands or actual functions.
# "limits" prints "limit" commands for things like cputime, etc.
# "modules" prints "zmodload" commands.
# "options" prints "setopt" commands.
# "variables" prints both shell and environment variables.
# "zstyles" prints "zstyle" commands
#
# "all" tries to find every useful setting under your shell.
# This is the default, and it's the same as typing all
# of the above options on the command line.
#
# CAVEATS:
# Assumes that you have the following programs in your search path:
# awk, cut, echo, grep, sed, sort
# Assumes that your C preprocessor lives in /lib/cpp or /usr/ccs/lib/cpp.
# Uses (and unsets) variables beginning with "reporter_".
# Won't work for versions of zsh that are older than 3.1.3 or so.
#
# RESTRICTIONS:
# DON'T: pretend you wrote it, sell it, or blame me if it breaks.
# DO: as ye will an' ye harm none.
# --Wiccan saying, I think
#
# BUGS:
# I'm sure there are more than a few. To be safe, run "zsh -f" before
# sourcing the output from this script. If you have "screen", you may
# want to use that, too; I hammered my terminal settings beyond repair
# when using an early version, and "screen" saved me from having to
# login on another terminal.
#
# HISTORY:
# The name was ripped off from the Emacs "reporter.el" function.
# The idea came from a mail message to the ZSH mailing list:
#
# Begin Configuration Section
#
reporter_OSVersion="`uname -s`_`uname -r`"
#
# Solaris 2.x
#
case ${reporter_OSVersion} in
SunOS_5.*)
CPP=${CPP:-/usr/ccs/lib/cpp}
AWK=${AWK:-nawk} # GNU AWK doesn't come standard :-(
;;
esac
#
# Default Values
#
CPP=${CPP:-/lib/cpp}
AWK=${AWK:-awk}
#
# End Configuration Section
#
reporter_do_all=yes
for reporter_each
do
case "$reporter_each"
in
ali*) reporter_do_aliases=yes; reporter_do_all=no ;;
b*) reporter_do_bindings=yes; reporter_do_all=no ;;
c*) reporter_do_compctl=yes; reporter_do_all=no ;;
f*) reporter_do_fun=yes; reporter_do_all=no ;;
l*) reporter_do_lim=yes; reporter_do_all=no ;;
m*) reporter_do_mod=yes; reporter_do_all=no ;;
o*) reporter_do_setopt=yes; reporter_do_all=no ;;
v*) reporter_do_vars=yes; reporter_do_all=no ;;
zs*|s*) reporter_do_zstyle=yes; reporter_do_all=no ;;
*) ;;
esac
done
#
# The "cshjunkiequotes" option can break some of the commands
# used in the remainder of this script, so we check for that first
# and disable it. Similarly "shwordsplit" and "kshoptionprint".
# We'll re-enable them later.
#
reporter_junkiequotes="no"
reporter_shwordsplit="no"
reporter_kshoptprint="no"
reporter_nounset="no"
if [[ -o cshjunkiequotes ]]
then
reporter_junkiequotes="yes"
unsetopt cshjunkiequotes
fi
if [[ -o shwordsplit ]]
then
reporter_shwordsplit="yes"
unsetopt shwordsplit
fi
if [[ -o kshoptionprint ]]
then
reporter_kshoptprint="yes"
unsetopt kshoptionprint
fi
if [[ -o nounset ]]
then
reporter_nounset="yes"
unsetopt nounset
fi
#
# UNAME
#
# This shows your system name. It's extremely system-dependent, so
# we need a way to find out what system you're on. The easiest
# way to do this is by using "uname", but not everyone has that,
# so first we go through the search path.
#
# If we don't find it, then the only thing I can think of is to
# check what's defined in your C compiler, and code in some exceptions
# for the location of "uname" or an equivalent. For example, Pyramid
# has "uname" only in the ATT universe. This code assumes that
# the "-a" switch is valid for "uname".
#
# This section of code sees what is defined by "cpp". It was
# originally written by brandy@tramp.Colorado.EDU (Carl Brandauer).
# Additional error checking and sed hacking added by Ken Phelps.
#
reporter_cppdef=(`strings -3 ${CPP} |
sed -n '
/^[a-zA-Z_][a-zA-Z0-9_]*$/{
s/.*/#ifdef &/p
s/.* \(.*\)/"\1";/p
s/.*/#endif/p
}
' | ${CPP} |sed '
/^[ ]*$/d
/^#/d
s/.*"\(.*\)".*/\1/'`)
reporter_uname=""
for reporter_each in `echo $PATH | sed -e 's/:/ /g'`
do
if [[ -x $reporter_each/uname ]]
then
reporter_uname="$reporter_each/uname"
break
fi
done
case "$reporter_uname"
in
"") reporter_uname="echo not found on this system" ;;
*) ;;
esac
for reporter_each in $reporter_cppdef
do
case "$reporter_each"
in
pyr) reporter_uname="/bin/att uname" ;;
*) ;;
esac
done
echo '# START zsh saveset'
echo '# uname: ' `eval $reporter_uname -a`
echo
unset reporter_cppdef
unset reporter_uname
unset reporter_each
#
# ALIASES
#
# Use "alias -L" to get a listing of the aliases in the form we want.
#
if [[ "$reporter_do_all" = "yes" || "$reporter_do_aliases" = "yes" ]]
then
echo '# Aliases.'
echo
alias -L
fi
#
# KEY BINDINGS
#
# The -L option does most of the work. The subshell is used to
# avoid modifying things that will be recorded later.
#
if [[ "$reporter_do_all" = "yes" || "$reporter_do_bindings" = "yes" ]]
then
echo
echo "# Key bindings."
echo
bindkey -lL | grep -v ' \.safe$'
(
alias bindkey=bindkey
bindkey () {
[[ "$1" == "-N" ]] || return
[[ "$2" == "--" ]] && shift
[[ "$2" == ".safe" ]] && return
echo
builtin bindkey -L -M -- "$2"
}
eval "`builtin bindkey -lL`"
)
fi
#
# COMPLETION COMMANDS
# Warning: this won't work for zsh-2.5.03.
#
if [[ "$reporter_do_all" = "yes" || "$reporter_do_compctl" = "yes" ]]
then
echo
echo "# Completions."
echo
compctl -L
fi
#
# FUNCTIONS
#
if [[ "$reporter_do_all" = "yes" || "$reporter_do_fun" = "yes" ]]
then
echo
echo "# Undefined functions."
echo
autoload + | ${AWK} '{print "autoload " $1}'
echo
echo "# Defined functions."
echo
(
unfunction `autoload +` 2>/dev/null
functions
)
fi
#
# LIMITS
#
# "cputime" has to be handled specially, because you can specify
# the time as just hours, or "minutes:seconds".
#
if [[ "$reporter_do_all" = "yes" || "$reporter_do_lim" = "yes" ]]
then
echo
echo '# Limits.'
echo
(
set X `limit | grep "cputime" | grep -v "unlimited" |
sed -e 's/:/ /g'`
if test "$#" -gt 1
then
hr=$3
min=$4
sec=$5
if test "$hr" -gt 0
then
echo "limit cputime ${hr}h"
else
echo "limit cputime $min:$sec"
fi
fi
)
limit | grep -v "cputime" | grep -v "unlimited" |
sed -e 's/Mb/m/' -e 's/Kb/k/' |
${AWK} 'NF > 1 {print "limit " $0}'
fi
#
# MODULE LOADING COMMANDS
#
if [[ "$reporter_do_all" = "yes" || "$reporter_do_mod" = "yes" ]]
then
echo
if ( zmodload ) >& /dev/null; then
echo "# Modules."
echo
zmodload -d -L
echo
zmodload -ab -L
echo
zmodload -ac -L
echo
zmodload -ap -L
echo
zmodload -L
else
echo "# Modules: zmodload not available."
fi
fi
#
# NON-ARRAY VARIABLES
#
# We run this in a subshell to preserve the parameter module state
# in the current shell. Also, reset the prompt to show you're now
# in a test shell.
#
if [[ "$reporter_do_all" = "yes" || "$reporter_do_vars" = "yes" ]]
then
echo
echo "# Non-array variables."
echo
(
zmodload -u `zmodload | grep parameter` 2>/dev/null
echo "ARGC=0"
eval `typeset + |
grep -v 'array ' |
grep -v 'association ' |
grep -v 'undefined ' |
grep -v ' ARGC$' |
grep -v '^reporter_' |
grep -wv '[!#$*0?@_-]$' |
sed -e 's/.* \(.*\)/print -r -- \1=${(qq)\1};/' \
-e 's/^\([^ ]*\)$/print -r -- \1=${(qq)\1};/'`
echo "prompt='test%'"
)
#
# ARRAY VARIABLES
#
# Run this in a subshell to preserve the parameter module state in
# the current shell.
#
echo
echo "# Array variables."
echo
(
zmodload -u `zmodload | grep parameter` 2>/dev/null
echo "argv=()"
eval `{ typeset + | grep 'array ' ;
typeset + | grep 'association ' } |
grep -v 'undefined ' |
grep -v ' argv$' |
grep -v ' reporter_' |
grep -v ' [!#$*0?@_-]$' |
sed 's/.* \(.*\)/print -r -- \1=\\\(${(qq)\1}\\\);/'`
)
#
# EXPORTED VARIABLES
#
# Run this in a subshell to preserve the parameter module state in
# the current shell.
#
echo
echo "# Exported variables."
echo
(
zmodload -u `zmodload | grep parameter` 2>/dev/null
export | grep -v "^'*"'[!#$*0?@_-]'"'*=" |
${AWK} -F'=' '{print "export " $1}'
)
fi
#
# SETOPT
#
# We exclude interactive because "setopt interactive" has no effect.
# A few special options are dealt with separately; see the comments
# near the start of the script.
#
if [[ "$reporter_do_all" = "yes" || "$reporter_do_setopt" = "yes" ]]
then
echo
echo '# Setopt.'
echo
(
setopt | grep -v 'interactive' | ${AWK} '{print "setopt " $0}'
case "$reporter_junkiequotes"
in
yes) echo "setopt cshjunkiequotes" ;;
*) ;;
esac
case "$reporter_shwordsplit"
in
yes) echo "setopt shwordsplit" ;;
*) ;;
esac
case "$reporter_kshoptprint"
in
yes) echo "setopt kshoptionprint" ;;
*) ;;
esac
case "$reporter_nounset"
in
yes) echo "setopt nounset" ;;
*) ;;
esac
) | sort
fi
#
# STYLES
#
if [[ "$reporter_do_all" = "yes" || "$reporter_do_zstyle" = "yes" ]]
then
echo
echo '# Styles.'
echo
zstyle -L
fi
echo
echo '# END zsh saveset'
#
# Don't put an exit here, or you'll get a nasty surprise when you
# source this thing. Get rid of variables created when processing
# command line.
#
unset reporter_do_all
unset reporter_do_aliases
unset reporter_do_bindings
unset reporter_do_compctl
unset reporter_do_fun
unset reporter_do_lim
unset reporter_do_setopt
unset reporter_do_vars
#
# Turn various options back on if necessary, in case run via ".".
#
case "$reporter_junkiequotes"
in
yes) setopt cshjunkiequotes ;;
*) ;;
esac
case "$reporter_shwordsplit"
in
yes) setopt shwordsplit ;;
*) ;;
esac
case "$reporter_kshoptprint"
in
yes) setopt kshoptionprint ;;
*) ;;
esac
case "$reporter_nounset"
in
yes) setopt nounset ;;
*) ;;
esac
unset reporter_junkiequotes
unset reporter_shwordsplit
unset reporter_kshoptprint
unset reporter_nounset
unset reporter_OSVersion
|