# 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} man/man1/${PORTNAME}.1.gz 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 6478807b2a3d8dc27461825a16cce70d echo x - shells/poshinit/distinfo sed 's/^X//' >shells/poshinit/distinfo << 'ce674f5dd39fb7629c07239d6657c6f1' XSHA256 (poshinit-1.0.tar.gz) = 59769d05ceb3061b7ce526ecc5585bf0267f9126db3bcb08a421a4c31b31803c XSIZE (poshinit-1.0.tar.gz) = 4188 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. 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 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 Xset -e Xclear Xmkdir .shell X X{ Xcat << 'EOF_aliases' X# This file is meant for implementation-independent aliases. X# Put implementation-specific aliases (eg: ls) in level_2/level_3 X 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 implementation-specific exports in level_2/level_3 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 implementation-specific functions in level_2/level_3 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 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 XEOF_bash X} > .bashrc X Xln .bashrc .bash_profile 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 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 X[ -f ~/.shell/aliases ] && . ~/.shell/aliases X[ -f ~/.shell/functions ] && . ~/.shell/functions X 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 L1="$EDITOR ~/.shell/level_1.all" 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 X[ -e ~/.shell/level_2 ] && alias L2="$EDITOR ~/.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# Xalias ls="ls --color=auto" X# 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[ -e ~/.shell/level_3 ] && alias L3="$EDITOR ~/.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 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 L1="$EDITOR ~/.shell/level_1" | c4)) Linux (distro-dependent -> level_3) Xalias L2="$EDITOR ~/.shell/level_2" | alias pfind="" X | alias pin="" X | alias pls="" 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 "16 October 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|-- 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(at least remember A and AA) X 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 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 XWhen using poshinit, remember that something is considered Ximplementation-independent if it works the same across FreeBSD / Linux X/ Cygwin. is an implementaion-dependent Xalias because it won't work on FreeBSD, where the alias would need to Xbe defined as . X XWith the above in mind : X X1) Put commands to be auto-executed upon login in ~/.shell/uponlogin X2) Put all implementation-independent aliases in ~/.shell/aliases X3) Put all implementation-independent exports in ~/.shell/exports X4) Put all implementation-independent functions in ~/.shell/functions X5) If you have any OS-dependent aliases/exports/functions, place them X as below: X X FreeBSD / Cygwin : under ~/.shell/level_2 X.br X Linux distribution-independent definitions under ~/.shell/level_2 X.br X Linux distribution-dependent definitions under ~/.shell/level_3 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 1 alias` should work too, but is currently unusable because Xit redirects as a shell built-in. X X.SH BUGS XNo known bugs. X X.SH AUTHOR XManish Jain (bourne.identity@hotmail.com) c65359b881c53a4982ce7f8cca733d84 exit