FreeBSD Bugzilla – Attachment 198995 Details for
Bug 232315
[NEW PORT] shells/poshinit : portable way of using the same shell environment with Bash / Zsh across FreeBSD / Linux / Cygwin
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
Revised shar archive for poshinit (attempt# 17)
poshinit.shar (text/plain), 17.61 KB, created by
bourne.identity@hotmail.com
on 2018-11-05 23:52:36 UTC
(
hide
)
Description:
Revised shar archive for poshinit (attempt# 17)
Filename:
MIME Type:
Creator:
bourne.identity@hotmail.com
Created:
2018-11-05 23:52:36 UTC
Size:
17.61 KB
patch
obsolete
># This is a shell archive. Save it in a file, remove anything before ># this line, and then unpack it by entering "sh file". Note, it may ># create directories; files and directories will be owned by you and ># have default permissions. ># ># This archive contains: ># ># shells/poshinit ># shells/poshinit/Makefile ># shells/poshinit/distinfo ># shells/poshinit/pkg-descr ># shells/poshinit/files ># shells/poshinit/files/poshinit ># shells/poshinit/files/poshinit.1 ># >echo c - shells/poshinit >mkdir -p shells/poshinit > /dev/null 2>&1 >echo x - shells/poshinit/Makefile >sed 's/^X//' >shells/poshinit/Makefile << '6478807b2a3d8dc27461825a16cce70d' >X# $FreeBSD$ >X >XPORTNAME= poshinit >XPORTVERSION= 1.0 >XCATEGORIES= shells >XMASTER_SITES= >X >XMAINTAINER= bourne.identity@hotmail.com >XCOMMENT= Portable shell environment across Bash/Zsh & across FreeBSD/Linux/Cygwin >X >XNO_BUILD= yes >XNO_ARCH= yes >X >XPLIST_FILES= bin/${PORTNAME} \ >X man/man1/${PORTNAME}.1.gz >X >XDISTFILES= >X >Xdo-install: >X ${INSTALL_SCRIPT} ${FILESDIR}/${PORTNAME} ${STAGEDIR}${PREFIX}/bin/ >X ${INSTALL_MAN} ${FILESDIR}/${PORTNAME}.1 ${STAGEDIR}${MANPREFIX}/man/man1 >X >X.include <bsd.port.mk> >6478807b2a3d8dc27461825a16cce70d >echo x - shells/poshinit/distinfo >sed 's/^X//' >shells/poshinit/distinfo << 'ce674f5dd39fb7629c07239d6657c6f1' >XTIMESTAMP = 1541461440 >XSHA256 (poshinit-1.0.tar.gz) = aed3d87e21a0bd61a592e49f357bbbbe27299ac7bfa8320232dfbf3ccf1ed1cd >XSIZE (poshinit-1.0.tar.gz) = 4837 >ce674f5dd39fb7629c07239d6657c6f1 >echo x - shells/poshinit/pkg-descr >sed 's/^X//' >shells/poshinit/pkg-descr << '2129c847ef038fffda5874a53c844d9d' >XYou want your shell stuff to work the same way even when you use a >Xdifferent shell, or even a different box. Right ? >X >XIf you use poshinit (Portable Shell Initialization), you can attain at >Xleast most of what you desire, perhaps even all. You can log out of Bash >Xand log in with Zsh (or vice versa) - and your aliases/exports/functions >Xwill continue to work as before. >X >XIt gets better - if someday you need to use a different box with a >Xdifferent OS, you can get your shell to work your 'normal' way in a >Xjiffy. Just save your $HOME/.shell directory on your primary box, and >Xpaste it over your second box's $HOME/.shell (after running poshinit >Xsetup script on the second box). The second box need not be the same >Xoperating system - poshinit works across FreeBSD / Linux / Cygwin. >X >XWWW: https://github.com/bourne-again/poshinit >2129c847ef038fffda5874a53c844d9d >echo c - shells/poshinit/files >mkdir -p shells/poshinit/files > /dev/null 2>&1 >echo x - shells/poshinit/files/poshinit >sed 's/^X//' >shells/poshinit/files/poshinit << 'dc2b66c0e9046aacdb87214597a61851' >X#!/bin/sh >X >Xzksh=false >Xeditor=vim >X >Xdie() >X{ >X [ $# -eq 0 ] && exit 1 >X >X [ $# -gt 1 ] && \ >X echo "error initiated at line $1 : >X $2" 1>&2 || \ >X echo "$1" 1>&2 >X >X exit 1 >X} >X >Xwhile [ $# -gt 0 ]; do >X case "$1" in >X --help) >X man poshinit >X exit 0 >X ;; >X >X *) >X die $LINENO "Invalid arg : $1" >X ;; >X esac >Xdone >X >Xcd $HOME || die $LINENO '`cd $HOME` failed. Aborting : - (' >X >Xecho 'I shall delete 3 globs under your $HOME : .bash* .zsh* .shell*' >Xecho 'If you are okay with that, press Enter. Else hit Ctrl+C to abort.' >Xread dummy >X >Xrm -rf .bash* .zsh* .shell* >X >Xok=false >X >Xwhile [ $ok = false ]; do >X echo "I am using $editor as your preferred text editor" >X echo "Is that okay with you ? (y/n):" >X >X read answer >X case "$answer" in >X y|Y|yes) >X ok=true >X ;; >X >X n|N|no) >X echo "Enter the command to use as editor" >X read editor >X ;; >X >X *) >X die $LINENO 'I could not make any sense of that. Aborting : - (' >X ;; >X esac >Xdone >X >X[ -z "$editor" ] && die $LINENO '$editor is null. Aborting : - (' >X >Xif ! which "$editor" > /dev/null; then >X echo 'Warning: bad `which $editor`' 1>&2 >X echo 'I am continuing with setup as such.' 1>&2 >X echo 'You can change your editor via ~/.shell/exports' 1>&2 >X echo 'Press Enter to continue' >X read dummy >Xfi >X >Xecho "Z shell by default begins array indexing at 1." >Xecho "Some system programs assume the default behaviour." >Xecho "But, if you need, you can change the default below." >Xecho "Would you like your Z to begin arrays at 0 (Bash-compatible) ? (y/n):" >X >Xread answer >Xcase "$answer" in >X y|Y|yes) >X zksh=true >X ;; >X >X n|N|no) >X zksh=false >X ;; >X >X *) >X die $LINENO 'I could not make any sense of that. Aborting : - (' >X ;; >Xesac >X >Xset -e >Xclear >Xmkdir .shell >X >X{ >Xcat << 'EOF_aliases' >X# This file is meant for implementation-independent aliases. >X# Put OS-specific aliases (eg: ls) in level_2 >X >Xalias editor="$EDITOR" >Xalias p="cd .." >Xalias p2="cd ../.." >Xalias rf="rm -rf" >X >X##### Above this line is what was pre-packaged. Below is the user section ###### >X >XEOF_aliases >X} > .shell/aliases >X >X{ >Xcat << 'EOF_exports' >X# This file is meant for implementation-independent exports. >X# Put OS-specific exports in level_2 >X >Xexport PATH=$PATH:$HOME/bin >X >X##### Above this line is what was pre-packaged. Below is the user section ###### >X >XEOF_exports >X} > .shell/exports >X >Xecho "export EDITOR=$editor" >> .shell/exports >X >X{ >Xcat << 'EOF_functions' >X# This file is meant for implementation-independent functions. >X# Put OS-specific functions in level_2 >X >X##### Above this line is what was pre-packaged. Below is the user section ###### >X >XEOF_functions >X} > .shell/functions >X >Xecho > .shell/uponlogin >Xecho > .shell/uponlogout >X >Xecho '[ -e ~/.shell/level_1.all ] && . ~/.shell/level_1.all' > .shellrc >Xecho '[ -e ~/.shell/uponlogin ] && . ~/.shell/uponlogin' >> .shellrc >X >X{ >Xcat << 'EOF_bash' >XPS1='`pwd` <<: ' >XHISTFILE="$HOME/.bash_history" >X[ -e ~/.shellrc ] && . ~/.shellrc >X[ -e ~/.shell/uponlogout ] && ln -sf ~/.shell/uponlogout ~/.bash_logout >XEOF_bash >X} > .bashrc >X >Xln .bashrc .bash_profile >X >X> .zshrc >X[ $zksh = true ] && echo "setopt KSH_ARRAYS" >> .zshrc >X >X{ >Xcat << 'EOF_zsh' >XPROMPT='%d <<: ' >XHISTFILE="$HOME/.zhistory" >Xsetopt hist_ignore_all_dups >X >Xbindkey "\e[1~" beginning-of-line >Xbindkey "\e[4~" end-of-line >Xbindkey "\e[5~" beginning-of-history >Xbindkey "\e[6~" end-of-history >Xbindkey "\e[3~" delete-char >Xbindkey "\e[2~" quoted-insert >Xbindkey "\e[5C" forward-word >Xbindkey "\eOc" emacs-forward-word >Xbindkey "\e[5D" backward-word >Xbindkey "\eOd" emacs-backward-word >Xbindkey "\ee[C" forward-word >Xbindkey "\ee[D" backward-word >Xbindkey "\^H" backward-delete-word >Xbindkey "\e[8~" end-of-line >Xbindkey "\e[7~" beginning-of-line >Xbindkey "\eOH" beginning-of-line >Xbindkey "\eOF" end-of-line >Xbindkey '^i' expand-or-complete-prefix >Xbindkey "\e[H" beginning-of-line >Xbindkey "\e[F" end-of-line >X >X[ -e ~/.shellrc ] && . ~/.shellrc >X[ -e ~/.shell/uponlogout ] && ln -sf ~/.shell/uponlogout ~/.zlogout >XEOF_zsh >X} >> .zshrc >X >X{ >Xcat << 'EOF1_all' >Xecho "$-" | grep -q 'i' || return >X >X# Exported definitions always get processed first : >X[ -f ~/.shell/exports ] && . ~/.shell/exports # define EDITOR here >X[ -f ~/.shell/aliases ] && . ~/.shell/aliases # define editor here >X[ -f ~/.shell/functions ] && . ~/.shell/functions >X >Xalias editor="$EDITOR" # restated, after ~/.aliases >Xalias A="editor ~/.shell/aliases" >Xalias AA=". ~/.shell/aliases" >Xalias E="editor ~/.shell/exports" >Xalias EE=". ~/.shell/exports" >Xalias F="editor ~/.shell/functions" >Xalias FF=". ~/.shell/functions" >Xalias I="editor ~/.shell/uponlogin" >Xalias II=". ~/.shell/uponlogin" >Xalias O="editor ~/.shell/uponlogout" >Xalias OO=". ~/.shell/uponlogout" >Xalias L1="editor ~/.shell/level_1.all" >Xalias L2="editor ~/.shell/level_2" >X >X# End of level_1 (Unix) global configuration. >X# All stuff below is for level_2, which branches for >X# freebsd / linux / cygwin : >X >Xif [ -L ~/.shell/level_2 ]; then >X for dist in freebsd linux cygwin; do >X if uname | grep -q -i $dist; then >X if ! readlink ~/.shell/level_2 | grep -q -i $dist; then >X if [ -f ~/.shell/level_2.${dist} ]; then >X cd ~/.shell >X ln -sf level_2.${dist} level_2 >X 1>/dev/null cd - >X else >X rm -f ~/.shell/level_2 >X fi >X fi >X >X break >X fi >X done >Xelse >X if ! [ -f ~/.shell/level_2 ]; then >X dist=`uname | tr '[:upper:]' '[:lower:]' | sed 's|_.*||'` >X >X if [ -f ~/.shell/level_2.${dist} ]; then >X cd ~/.shell >X ln -s level_2.${dist} level_2 >X 1>/dev/null cd - >X fi >X fi >Xfi >X >X[ -e ~/.shell/level_3 ] && rm -f ~/.shell/level_3 >X[ -e ~/.shell/level_2 ] && . ~/.shell/level_2 >XEOF1_all >X} > .shell/level_1.all >X >X{ >Xcat << 'EOF2_freebsd' >X# This file is meant for FreeBSD-specific definitions. >X# Put implementation-independent definitions in the files >X# [$HOME/.shell/]aliases|exports|functions >X >Xalias ls="ls -G" >Xalias pfind="pkg search" >Xalias pin="pkg install" >Xalias pls="pkg query %n" >X >X# Restart your terminal to have changes to this file take effect # >XEOF2_freebsd >X} > .shell/level_2.freebsd >X >X{ >Xcat << 'EOF2_cygwin' >X# This file is meant for Cygwin-specific definitions. >X# Put implementation-independent definitions in the files >X# [$HOME/.shell/]aliases|exports|functions >X >Xalias ls="ls --color=auto" >X >X# Restart your terminal to have changes to this file take effect # >XEOF2_cygwin >X} > .shell/level_2.cygwin >X >X{ >Xcat << 'EOF2_linux' >X# This file is meant for Linux-specific definitions. >X# Put implementation-independent definitions in the files >X# [$HOME/.shell/]aliases|exports|functions >X >X# <distro-independent-definitions> >Xalias ls="ls --color=auto" >Xalias L3="editor ~/.shell/level_3" >X# </distro-independent-definitions> >X >X# End of distro-independent block. >X# All stuff below is for Level 3, which branches for distro flavours: >X# arch / debian / redhat >X >Xflavour="" >X >Xif [ -f /etc/arch-release ]; then >X flavour=arch >Xelif [ -f /etc/debian_version ]; then >X flavour=debian >Xelif [ -f /etc/redhat-release ]; then >X flavour=redhat >Xfi >X >X[ -n "$flavour" ] || return >X >Xif [ -L ~/.shell/level_3 ]; then >X if ! readlink ~/.shell/level_3 | grep -q -i $flavour; then >X if [ -f ~/.shell/level_3.${flavour} ]; then >X cd ~/.shell >X ln -sf level_3.${flavour} level_3 >X 1>/dev/null cd - >X else >X rm -f ~/.shell/level_3 >X fi >X fi >Xelse >X if ! [ -f ~/.shell/level_3 ]; then >X if [ -f ~/.shell/level_3.${flavour} ]; then >X cd ~/.shell >X ln -s level_3.${flavour} level_3 >X 1>/dev/null cd - >X fi >X fi >Xfi >X >X[ -e ~/.shell/level_3 ] && . ~/.shell/level_3 >X >X# Restart your terminal to have changes to this file take effect # >XEOF2_linux >X} > .shell/level_2.linux >X >X{ >Xcat << 'EOF3_arch' >Xalias pfind="pacman -Ss" >Xalias pin="pacman -S" >Xalias pls="pacman --query" >X >X# Restart your terminal to have changes to this file take effect # >XEOF3_arch >X} > .shell/level_3.arch >X >X{ >Xcat << 'EOF3_debian' >Xalias pfind="apt search" >Xalias pin="apt install" >Xalias pls="apt list --installed" >X >X# Restart your terminal to have changes to this file take effect # >XEOF3_debian >X} > .shell/level_3.debian >X >X{ >Xcat << 'EOF3_redhat' >Xalias pfind="yum search" >Xalias pin="yum install" >Xalias pls="yum list installed" >X >X# Restart your terminal to have changes to this file take effect # >XEOF3_redhat >X} > .shell/level_3.redhat >X >Xset +e >X >X{ >Xcat << 'EOF_final' >XI have created 3 kinds of aliases, as noted underneath. >X >XA) implementation-independent : | C) implementation-dependent : >X(under $HOME/.shell/aliases) | (under the highest possible level file) >Xalias editor="$EDITOR" | <Level 1 is considered highest> >Xalias p="cd .." | >Xalias p2="cd ../.." | c1)) For FreeBSD (under .shell/level_2) >Xalias rf="rm -rf" | alias ls="ls -G" >X | alias pfind="pkg search" >XB) poshinit-specific : | alias pin="pkg install" >X(under $HOME/.shell/level_1.all) | alias pls="pkg query %n" >Xalias A="editor ~/.shell/aliases" | >Xalias AA=". ~/.shell/aliases" | c2)) For Cygwin (under .shell/level_2) >Xalias E="editor ~/.shell/exports" | alias ls="ls --color=auto" >Xalias EE=". ~/.shell/exports" | >Xalias F="editor ~/.shell/functions" | c3)) Linux (distro-independent -> level_2) >Xalias FF=". ~/.shell/functions" | alias ls="ls --color=auto" >Xalias I="editor ~/.shell/uponlogin" | alias L3="editor ~/.shell/level_3" >Xalias II=". ~/.shell/uponlogin" | >Xalias O="editor ~/.shell/uponlogout"| c4)) Linux (distro-dependent -> level_3) >Xalias OO=". ~/.shell/uponlogout" | alias pfind="<search for package>" >Xalias L1="editor ~/.shell/level_1" | alias pin="<install package>" >Xalias L2="editor ~/.shell/level_2" | alias pls="<list installed package>" >X >XPortable shell initialization layout created successfully. >XTo have it take effect, logout and login again (or restart your terminal). >XThis complete message has been saved as $HOME/poshinit-msg.txt >XEOF_final >X} | tee poshinit-msg.txt >X >Xexit 0 >dc2b66c0e9046aacdb87214597a61851 >echo x - shells/poshinit/files/poshinit.1 >sed 's/^X//' >shells/poshinit/files/poshinit.1 << 'c65359b881c53a4982ce7f8cca733d84' >X.TH man 1 "06 November 2018" "1.0" "poshinit man page" >X >X.SH NAME >Xposhinit \- Portable Shell Initialization >X >X.SH SYNOPSIS >Xposhinit \- setup a portable shell environment that you can reuse across >XBash/Zsh and across multiple operating systems (FreeBSD/Linux/Cygwin) >X >X.SH DESCRIPTION >Xposhinit is a convenient way of setting up and then reusing your master >Xshell environment when you work with Bash or Zsh. It works across all >Xmajor Open Source implementations (FreeBSD / Linux / Cygwin). >X >XWhen you run the setup script, it just creates the filesystem layout it >Xneeds. If you later switch your shell from Bash to Zsh or vice versa, >Xthe layout ensures that your new shell works just as the prior one. >X >XWhen you use poshinit the first time (to create your master shell >Xenvironment), the major facilities are the aliases A (edit your aliases) >Xand AA (insert your aliases into the shell environment). Aliases are >Xstored under ~/.shell/aliases. >X >XSimilar hacks exist for exports (E/EE), functions (F/FF) and commands to >Xauto-execute on login, a.k.a. 'uponlogin' (I/II). >X >XThe first time you use poshinit, you have to do the hard work in >Xsetting up your complete shell environment. But once you have done the >Xhard work, you can get the same environment every time in future with >Xvery little effort - just run poshinit setup script, and copy over your >Xmaster ~/.shell directory (or maybe even modify the poshinit script). >X >XIt is nice to know a bit about the layout utilized by poshinit. >X >X~/.bashrc is hard-linked as ~/.bash_profile >X.br >X~/.zshrc and ~/.bashrc source a common file ~/.shellrc >X >XWhen using poshinit, do not modify .bashrc / .bash_profile / .zshrc >Xyourself. Instead, modify the tree under ~/.shell (see below). >X >X~/.shellrc uses the following tree in which the symbolic links >Xlevel_2 and level_3 get populated dynamically at the time of login. >X(Linux systems use level_2 & level_3. FreeBSD/Cygwin use level_2 only.) >X >X~/.shell >X.br >X|-- aliases >X.br >X|-- exports >X.br >X|-- functions >X.br >X|-- uponlogin >X.br >X|-- uponlogout >X.br >X|-- level_1.all >X.br >X|-- level_2 -> ? >X.br >X|-- level_2.cygwin >X.br >X|-- level_2.freebsd >X.br >X|-- level_2.linux >X.br >X|-- level_3 -> ? >X.br >X|-- level_3.arch >X.br >X|-- level_3.debian >X.br >X|-- level_3.redhat >X >XThe following utility aliases are available in a poshinit installation: >X >Xalias editor="$EDITOR" # ~/.shell/exports states EDITOR >X.br >Xalias A="editor ~/.shell/aliases" >X.br >Xalias AA=". ~/.shell/aliases" >X.br >Xalias E="editor ~/.shell/exports" >X.br >Xalias EE=". ~/.shell/exports" >X.br >Xalias F="editor ~/.shell/functions" >X.br >Xalias FF=". ~/.shell/functions" >X.br >Xalias I="editor ~/.shell/uponlogin" >X.br >Xalias II=". ~/.shell/uponlogin" >X.br >Xalias O="editor ~/.shell/uponlogout" >X.br >Xalias OO=". ~/.shell/uponlogout" >X.br >Xalias L1="editor ~/.shell/level_1.all" >X.br >Xalias L2="editor ~/.shell/level_2" >X.br >Xalias L3="editor ~/.shell/level_3" # only for Linux >X >XWhile it should not be difficult to commit all the above hacks to >Xmemory, at least remember the three most important ones: >X >XA Edit portable aliases >X.br >XAA Insert portable aliases into the shell environment >X.br >XL2 Edit OS-specific definitions (aliases/exports/functions) >X >XWhen using poshinit, remember that something is considered >Ximplementation-independent (and thus fully portable) if it works the >Xsame across FreeBSD / Linux / Cygwin. <alias ls="ls --color=auto"> is an >Ximplementaion-dependent alias because it won't work on FreeBSD, where >Xthe alias would need to be defined as <alias ls="ls -G">. >X >XWith the above in mind : >X >X1) Put commands to be auto-executed upon login in ~/.shell/uponlogin >Xand all commands to be auto-executed upon logout in ~/.shell/uponlogout >X.br >X2) Put all OS-independent aliases in ~/.shell/aliases >X.br >X3) Put all OS-independent exports in ~/.shell/exports >X.br >X4) Put all OS-independent functions in ~/.shell/functions >X.br >X5) Place all OS-dependent definitions ~/.shell/level_2 >X >XIf you have any definition that depends not just on the OS but >Xfurther on its flavours, place it under ~/.shell/level_3. So if >Xyou are on a Linux box and are working with a definition that is >Xdistro-dependent (eg: an alias to <list all installed packages>), >Xplace the definition under ~/.shell/level_3, not ~/.shell/level_2. >X~/.shell/level_2 is reserved for stuff that works on the OS >Xwithout concern for its flavours. >X >X.SH OPTIONS >XThe poshinit command does not take any options. >X >X.SH SEE ALSO >Xenv(1) >X >XRunning the bare command `alias` displays all aliases active. >X.br >X`man alias` should work too, but is currently unusable because >Xit redirects as a shell built-in. >X >X.SH BUGS >X1) Default (level_3) yum alias definitions are CentOS-based and may >Xnot always work out-of-the-box under RedHat distributions. If so, >Xjust use L3 to edit those aliases. >X >X2) A (level_3) branch for the Cygwin fork Babun should perhaps exist, >Xbut currently does not. >X >X.SH AUTHOR >XManish Jain (bourne.identity@hotmail.com) >c65359b881c53a4982ce7f8cca733d84 >exit >
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Raw
Actions:
View
Attachments on
bug 232315
:
198201
|
198202
|
198203
|
198216
|
198217
|
198218
|
198230
|
198231
|
198232
|
198245
|
198246
|
198247
|
198278
|
198279
|
198280
|
198282
|
198283
|
198284
|
198295
|
198296
|
198297
|
198321
|
198329
|
198625
|
198679
|
198705
|
198707
|
198772
|
198825
|
198870
|
198916
|
198995
|
198999
|
199152
|
199189
|
199343
|
199349
|
199424
|
199900
|
200615