From f4dfbb58c7d47a584cb7c9aed1c0274f64b44dc8 Mon Sep 17 00:00:00 2001 From: Wes Turner Date: Tue, 25 Aug 2015 09:52:09 -0500 Subject: [PATCH 01/12] DOC: autogenerated usage docs --- docs/usage/bash_conf.txt | 5 ++- scripts/_dotfiles_bash.log.sh | 73 +++++++++++++++++++---------------- scripts/_dotfiles_zsh.log.sh | 7 +++- 3 files changed, 49 insertions(+), 36 deletions(-) diff --git a/docs/usage/bash_conf.txt b/docs/usage/bash_conf.txt index bed65922..6a1be430 100644 --- a/docs/usage/bash_conf.txt +++ b/docs/usage/bash_conf.txt @@ -543,8 +543,9 @@ # psch -- 'ps uxaw -c | head' # psm -- 'ps uxaw -m' # psmh -- 'ps uxaw -m | head' - # pyg -- pygmentize - # shtop -- 'sudo htop' + # pyg -- pygmentize [pip install --user pygments] + # catp -- pygmentize [pip install --user pygments] + # shtop -- 'sudo htop' [apt-get/yum install -y htop] # t -- 'tail' # tf -- 'tail -f' # xclipc -- 'xclip -selection c' diff --git a/scripts/_dotfiles_bash.log.sh b/scripts/_dotfiles_bash.log.sh index 28c38f81..2420c2f2 100644 --- a/scripts/_dotfiles_bash.log.sh +++ b/scripts/_dotfiles_bash.log.sh @@ -103,7 +103,7 @@ fi ## 00-bashrc.before.sh -- bash dotfiles configuration root # source ${__DOTFILES}/etc/bash/00-bashrc.before.sh -- dotfiles_reload() # -dotfiles_reload() { +function dotfiles_reload { # dotfiles_reload() -- (re)load the bash configuration # $__DOTFILES (str): -- path to the dotfiles symlink (~/-dotfiles) @@ -292,13 +292,13 @@ dotfiles_reload() { source ${conf}/99-bashrc.after.sh } -dr() { +function dr { # dr() -- dotfiles_reload dotfiles_reload $@ } # ds() -- print dotfiles_status() -dotfiles_main() { +function dotfiles_main { dotfiles_reload } @@ -1263,16 +1263,16 @@ function lsve { function backup_virtualenv { # backup_virtualenv() -- backup VIRTUAL_ENV_NAME $1 to [$2] - venv=${1} - _date=$(date +'%FT%T%z') - bkpdir=${2:-"${WORKON_HOME}/_venvbkps/${_date}"} - test -d ${bkpdir} || mkdir -p ${bkpdir} - archivename="venvbkp.${venv}.${_date}.tar.gz" + local venvstr="${1}" + local _date="$(date +'%FT%T%z')" + bkpdir="${2:-"${WORKON_HOME}/_venvbkps/${_date}"}" + test -d "${bkpdir}" || mkdir -p "${bkpdir}" + archivename="venvstrbkp.${venvstr}.${_date}.tar.gz" archivepath="${bkpdir}/${archivename}" - (cd ${WORKON_HOME}; \ - tar czf ${archivepath} ${venv} \ - && echo "${archivename}" \ - || (echo "err: ${venv} (${archivename})" 1>&2)) + (cd "${WORKON_HOME}" \ + tar czf "${archivepath}" "${venvstr}" \ + && echo "${archivename}" \ + || (echo "err: ${venvstr} (${archivename})" >&2)) } function backup_virtualenvs { @@ -1280,16 +1280,16 @@ function backup_virtualenvs { date=$(date +'%FT%T%z') bkpdir=${1:-"${WORKON_HOME}/_venvbkps/${date}"} echo BKPDIR="${bkpdir}" - test -d ${bkpdir} || mkdir -p ${bkpdir} + test -d "${bkpdir}" || mkdir -p "${bkpdir}" lsvirtualenvs venvs=$(lsvirtualenvs) - (cd ${WORKON_HOME}; \ + (cd "${WORKON_HOME}"; \ for venv in ${venvs}; do - backup_virtualenv ${venv} ${bkpdir} \ - 2>> ${bkpdir}/venvbkps.err \ - | tee -a ${bkpdir}/venvbkps.list + backup_virtualenv "${venv}" "${bkpdir}" \ + 2>> "${bkpdir}/venvbkps.err" \ + | tee -a "${bkpdir}/venvbkps.list" done) - cat ${bkpdir}/venvbkps.err + cat "${bkpdir}/venvbkps.err" echo BKPDIR="${bkpdir}" } @@ -1314,24 +1314,24 @@ function _rebuild_virtualenv { find -E "${_PYSITE}" -iname 'easy_install*' -delete find -E "${_PYSITE}" -iname 'python*' -delete declare -f 'deactivate' 2>&1 /dev/null && deactivate - mkvirtualenv -i setuptools -i wheel -i pip ${VENVSTR} + mkvirtualenv -i setuptools -i wheel -i pip "${VENVSTR}" #mkvirtualenv --clear would delete ./lib/python/site-packages - workon ${VENVSTR} && \ - we ${VENVSTR} + workon "${VENVSTR}" && \ + we "${VENVSTR}" _BIN="${VIRTUAL_ENV}/bin" if [ "${_BIN}" == "/bin" ]; then - echo "err: _BIN='${_BIN}'" + echo "err: _BIN=${_BIN}" return 1 fi - find ${_BIN} -type f | grep -v '.bak$' | grep -v 'python*$' \ + find "${_BIN}" -type f | grep -v '.bak$' | grep -v 'python*$' \ | xargs head -n1 - find ${_BIN} -type f | grep -v '.bak$' | grep -v 'python*$' \ + find "${_BIN}" -type f | grep -v '.bak$' | grep -v 'python*$' \ | LC_ALL=C xargs sed -i.bak -E 's,^#!.*python.*,#!'${_BIN}'/python,' - find $_BIN -name '*.bak' -delete + find "${_BIN}" -name '*.bak' -delete - find ${_BIN} -type f | grep -v '.bak$' | grep -v 'python*$' \ + find "${_BIN}" -type f | grep -v '.bak$' | grep -v 'python*$' \ | xargs head -n1 echo " # TODO: adjust paths beyond the shebang @@ -1363,7 +1363,7 @@ function _setup_virtualenvwrapper { -if [[ "$BASH_SOURCE" == "$0" ]]; then +if [[ "${BASH_SOURCE}" == "$0" ]]; then _setup_virtualenvwrapper else #if [ -z "${VIRTUALENVWRAPPER_SCRIPT}" ]; then @@ -5077,13 +5077,20 @@ _loadaliases () { # psmh -- 'ps uxaw -m | head' alias psmh='ps uxaw -m | head' fi - - # pyg -- pygmentize + # pyg -- pygmentize [pip install --user pygments] alias pyg='pygmentize' - alias pygp'pygmentize -l python' + alias pygp='pygmentize -l python' + alias pygj='pygmentize -l javascript' + alias pygh='pygmentize -l html' - # shtop -- 'sudo htop' + # catp -- pygmentize [pip install --user pygments] + alias catp='pygmentize' + alias catpp='pygmentize -l python' + alias catpj='pygmentize -l javascript' + alias catph='pygmentize -l html' + + # shtop -- 'sudo htop' [apt-get/yum install -y htop] alias shtop='sudo htop' # t -- 'tail' alias t='tail' @@ -5093,7 +5100,6 @@ _loadaliases () { alias xclipc='xclip -selection c' } _loadaliases -bash: alias: pygppygmentize -l python: not found @@ -5751,9 +5757,10 @@ _APP='dotfiles' _WRD='/home/wturner/-wrk/-ve27/dotfiles/src/dotfiles' _USRLOG='/home/wturner/-wrk/-ve27/dotfiles/-usrlog.log' _TERM_ID='#testing' -PATH='/home/wturner/-wrk/-ve27/wrdrd/bin:/home/wturner/-dotfiles/scripts:/usr/lib64/qt-3.3/bin:/usr/local/bin:/usr/local/sbin:/usr/bin:/usr/sbin:/bin:/sbin:/home/wturner/.local/bin:/home/wturner/bin' +PATH='/home/wturner/-wrk/-ve27/dotfiles/bin:/home/wturner/-dotfiles/scripts:/usr/lib64/qt-3.3/bin:/usr/local/bin:/usr/local/sbin:/usr/bin:/usr/sbin:/bin:/sbin:/home/wturner/.local/bin:/home/wturner/bin' __DOTFILES='/home/wturner/-dotfiles' # +_NOTE='TODO: just the pip deps for netstat' ## ### diff --git a/scripts/_dotfiles_zsh.log.sh b/scripts/_dotfiles_zsh.log.sh index 9452c9ff..195f12ec 100644 --- a/scripts/_dotfiles_zsh.log.sh +++ b/scripts/_dotfiles_zsh.log.sh @@ -5569,6 +5569,10 @@ SSH_AGENT_PID=30357; export SSH_AGENT_PID; #echo Agent pid 30357; grep: warning: GREP_OPTIONS is deprecated; please use an alias or script grep: warning: GREP_OPTIONS is deprecated; please use an alias or script +SSH_AUTH_SOCK=/tmp/ssh-yNoaOfzVdDpf/agent.11645; export SSH_AUTH_SOCK; +SSH_AGENT_PID=11647; export SSH_AGENT_PID; +#echo Agent pid 11647; +starting ssh-agent... # tidy up after ourselves unfunction _plugin__start_agent @@ -8538,9 +8542,10 @@ _APP='dotfiles' _WRD='/home/wturner/-wrk/-ve27/dotfiles/src/dotfiles' _USRLOG='/home/wturner/-wrk/-ve27/dotfiles/-usrlog.log' _TERM_ID='#testing' -PATH='/home/wturner/bin:/usr/local/bin:/home/wturner/-wrk/-ve27/wrdrd/bin:/home/wturner/-dotfiles/scripts:/usr/lib64/qt-3.3/bin:/usr/local/bin:/usr/local/sbin:/usr/bin:/usr/sbin:/bin:/sbin:/home/wturner/.local/bin:/home/wturner/bin' +PATH='/home/wturner/bin:/usr/local/bin:/home/wturner/-wrk/-ve27/dotfiles/bin:/home/wturner/-dotfiles/scripts:/usr/lib64/qt-3.3/bin:/usr/local/bin:/usr/local/sbin:/usr/bin:/usr/sbin:/bin:/sbin:/home/wturner/.local/bin:/home/wturner/bin' __DOTFILES='/home/wturner/-dotfiles' # +_NOTE='TODO: just the pip deps for netstat' ## # 99-zsh.after.sh From 64d81b6eae80d5c618e2ab4ab76a8d91c1078877 Mon Sep 17 00:00:00 2001 From: Wes Turner Date: Sun, 6 Sep 2015 23:49:30 -0500 Subject: [PATCH 02/12] BUG,SEC: 29-bashrc.vimpagers.sh: quoting --- etc/bash/29-bashrc.vimpagers.sh | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/etc/bash/29-bashrc.vimpagers.sh b/etc/bash/29-bashrc.vimpagers.sh index 0fc6ba72..8c3b7e8c 100644 --- a/etc/bash/29-bashrc.vimpagers.sh +++ b/etc/bash/29-bashrc.vimpagers.sh @@ -3,7 +3,7 @@ _configure_lesspipe() { # _configure_lesspipe() -- (less | lessv) - lesspipe=$(which lesspipe.sh 2>/dev/null || false) + lesspipe="$(which lesspipe.sh 2>/dev/null)" if [ -n "${lesspipe}" ]; then eval "$(${lesspipe})" fi @@ -15,7 +15,7 @@ vimpager() { # vimpager() -- call vimpager _PAGER=$(which vimpager) if [ -x "${_PAGER}" ]; then - ${_PAGER} $@ + "${_PAGER}" $@ else echo "error: vimpager not found. (see lessv: 'lessv $@')" fi @@ -28,7 +28,7 @@ lessv () { if [ $# -eq 0 ]; then if [ -n "$VIMPAGER_SYNTAX" ]; then #read stdin - ${VIMBIN} --cmd "let g:tinyvim=1" \ + "${VIMBIN}" --cmd "let g:tinyvim=1" \ --cmd "runtime! macros/less.vim" \ --cmd "set nomod" \ --cmd "set noswf" \ @@ -37,7 +37,7 @@ lessv () { -c "set syntax=${VIMPAGER_SYNTAX}" \ - else - ${VIMBIN} --cmd "let g:tinyvim=1" \ + "${VIMBIN}" --cmd "let g:tinyvim=1" \ --cmd "runtime! macros/less.vim" \ --cmd "set nomod" \ --cmd "set noswf" \ @@ -46,7 +46,7 @@ lessv () { - fi elif [ -n "$VIMPAGER_SYNTAX" ]; then - ${VIMBIN} \ + "${VIMBIN}" \ --cmd "let g:tinyvim=1" \ --cmd "runtime! macros/less.vim" \ --cmd "set nomod" \ @@ -57,7 +57,7 @@ lessv () { ${@} else - ${VIMBIN} \ + "${VIMBIN}" \ --cmd "let g:tinyvim=1" \ --cmd "runtime! macros/less.vim" \ --cmd "set nomod" \ @@ -78,12 +78,12 @@ lessv () { lessg() { # lessg() -- less with less.vim and gvim / mvim - VIMBIN=${GUIVIMBIN} lessv $@ + VIMBIN="${GUIVIMBIN}" lessv $@ } lesse() { # lesse() -- less with current venv's vim server - ${EDITOR_} $@ + "${GUIVIMBIN}" --servername ${VIRTUAL_ENV_NAME:-"/"} --remote-tab ${@}; } manv() { @@ -93,7 +93,7 @@ manv() { /usr/bin/man else #/usr/bin/whatis "$@" >/dev/null - $(which vim) \ + "$(which vim)" \ --noplugin \ -c "runtime ftplugin/man.vim" \ -c "Man $*" \ @@ -109,7 +109,7 @@ mang() { if [ $# -eq 0 ]; then /usr/bin/man else - ${GUIVIMBIN} \ + "${GUIVIMBIN}" \ --noplugin \ -c "runtime ftplugin/man.vim" \ -c "Man $*" \ From d5971c5c3af22df9170c0bb8769e627d3d6237ad Mon Sep 17 00:00:00 2001 From: Wes Turner Date: Mon, 7 Sep 2015 00:24:10 -0500 Subject: [PATCH 03/12] SEC,DOC: 00-bashrc.before.sh: quoting --- etc/bash/00-bashrc.before.sh | 71 +++++++++++++++++++----------------- 1 file changed, 38 insertions(+), 33 deletions(-) diff --git a/etc/bash/00-bashrc.before.sh b/etc/bash/00-bashrc.before.sh index 73614f64..36f9daef 100644 --- a/etc/bash/00-bashrc.before.sh +++ b/etc/bash/00-bashrc.before.sh @@ -11,56 +11,56 @@ function dotfiles_reload { export __WRK="${HOME}/-wrk" - if [ -n $__DOTFILES ]; then - export __DOTFILES=${__DOTFILES} + if [ -n "${__DOTFILES}" ]; then + export __DOTFILES="${__DOTFILES}" else - _dotfiles_src=${WORKON_HOME}/dotfiles/src/dotfiles - _dotfiles_link=${HOME}/-dotfiles + _dotfiles_src="${WORKON_HOME}/dotfiles/src/dotfiles" + _dotfiles_link="${HOME}/-dotfiles" - if [ -d $_dotfiles_link ]; then - __DOTFILES=${_dotfiles_link} - elif [ -d $_dotfiles_src ]; then - __DOTFILES=${_dotfiles_src} + if [ -d "${_dotfiles_link}" ]; then + __DOTFILES="${_dotfiles_link}" + elif [ -d "${_dotfiles_src}" ]; then + __DOTFILES="${_dotfiles_src}" fi - export __DOTFILES=${__DOTFILES} + export __DOTFILES="${__DOTFILES}" fi - conf=${__DOTFILES}/etc/bash + conf="${__DOTFILES}/etc/bash" # ## 01-bashrc.lib.sh -- useful bash functions (paths) # lspath() -- list every file along $PATH # realpath() -- readlink -f (python os.path.realpath) # walkpath() -- list every directory along ${1:-"."} - source ${conf}/01-bashrc.lib.sh + source "${conf}/01-bashrc.lib.sh" # ## 02-bashrc.platform.sh -- platform things - source ${conf}/02-bashrc.platform.sh + source "${conf}/02-bashrc.platform.sh" detect_platform # detect_platform() -- set $__IS_MAC or $__IS_LINUX if [ -n "${__IS_MAC}" ]; then - export PATH=$(echo ${PATH} | sed 's,/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin,/usr/sbin:/sbin:/bin:/usr/local/bin:/usr/bin,') + export PATH="$(echo ${PATH} | sed 's,/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin,/usr/sbin:/sbin:/bin:/usr/local/bin:/usr/bin,')" ## 03-bashrc.darwin.sh - source ${conf}/03-bashrc.darwin.sh + source "${conf}/03-bashrc.darwin.sh" fi # ## 04-bashrc.TERM.sh -- set $TERM and $CLICOLOR - source ${conf}/04-bashrc.TERM.sh + source "${conf}/04-bashrc.TERM.sh" # ## 05-bashrc.dotfiles.sh -- dotfiles # $__DOTFILES (str): -- path to the dotfiles symlink (~/.dotfiles) # dotfiles_status() -- print dotfiles variables # ds() -- print dotfiles variables - source ${conf}/05-bashrc.dotfiles.sh + source "${conf}/05-bashrc.dotfiles.sh" dotfiles_add_path # ## 06-bashrc.completion.sh -- configure bash completion - source ${conf}/06-bashrc.completion.sh + source "${conf}/06-bashrc.completion.sh" # ## @@ -75,7 +75,7 @@ function dotfiles_reload { # _setup_python() -- configure PYTHONSTARTUP # _setup_pip() -- configure PIP_REQUIRE_VIRTUALENV # _setup_pyenv() -- setup pyenv PYENV_ROOT and eval (manual) - source ${conf}/07-bashrc.python.sh + source "${conf}/07-bashrc.python.sh" # ## 08-bashrc.conda.sh -- conda @@ -85,7 +85,7 @@ function dotfiles_reload { # $2 (str): (optional) CONDA_ROOT_PATH (or '27' or '34') # $CONDA_ROOT (str): path to conda install (~/-wrk/-conda34) # $CONDA_ENVS_PATH (str): path to condaenvs directory (~/-wrk/-ce34) [conda] - source ${conf}/08-bashrc.conda.sh + source "${conf}/08-bashrc.conda.sh" # ## 07-bashrc.virtualenvwrapper.sh -- virtualenvwrapper @@ -97,12 +97,12 @@ function dotfiles_reload { # rebuild_virtualenv($VENVSTR) -- rebuild $WORKON_HOME/$VENVSTR # rebuild_virtualenvs() -- rebuild $WORKON_HOME/* # TODO: restore_virtualenv($BACKUPVENVSTR, [$NEWVENVSTR]) - source ${conf}/07-bashrc.virtualenvwrapper.sh + source "${conf}/07-bashrc.virtualenvwrapper.sh" # ## 08-bashrc.gcloud.sh -- gcloud: Google Cloud SDK # _setup_google_cloud() -- setup google cloud paths - source ${conf}/08-bashrc.gcloud.sh + source "${conf}/08-bashrc.gcloud.sh" # ## 10-bashrc.venv.sh -- venv: virtualenvwrapper extensions @@ -117,12 +117,12 @@ function dotfiles_reload { # we dotfiles # we dotfiles etc/bash; cdw; ds; # ls -altr; lll; cd ~; ew etc/bash/*.sh # type workon_venv; which venv.py; venv.py --help - source ${conf}/10-bashrc.venv.sh + source "${conf}/10-bashrc.venv.sh" # # ## 11-bashrc.venv.pyramid.sh -- venv-pyramid: pyramid-specific config - source ${conf}/11-bashrc.venv.pyramid.sh + source "${conf}/11-bashrc.venv.pyramid.sh" # ## 20-bashrc.editor.sh -- $EDITOR configuration @@ -131,7 +131,7 @@ function dotfiles_reload { # e() -- open paths in current EDITOR_ [scripts/e] # ew() -- open paths relative to $_WRD in current EDITOR_ [scripts/ew] # (~ cd $_WRD; $EDITOR_ ${@}) + tab completion - source ${conf}/20-bashrc.editor.sh + source "${conf}/20-bashrc.editor.sh" # ## 20-bashrc.vimpagers.sh -- $PAGER configuration # $PAGER (str): cmdstring to run pager (less/vim) @@ -139,8 +139,13 @@ function dotfiles_reload { # VIMPAGER_SYNTAX="python" lessv # lessg() -- open in a gvim with less.vim # VIMPAGER_SYNTAX="python" lessv - # lesse() -- open with $EDITOR_ - source ${conf}/29-bashrc.vimpagers.sh + # lesse() -- open with $EDITOR_ (~e) + # manv() -- open manpage with vim + # mang() -- open manpage with gvim + # mane() -- open manpage with $EDITOR_ (~e) + # + # TODO: GIT_PAGER="/usr/bin/less -R | /usr/bin/cat" + source "${conf}/29-bashrc.vimpagers.sh" # ## 30-bashrc.usrlog.sh -- $_USRLOG configuration @@ -162,33 +167,33 @@ function dotfiles_reload { # egrep $@ "${__USRLOG}" "${WORKON_HOME}/*/-usrlog.log" # ugrin -- grin current usrlog: grin $@ ${_USRLOG} # ugrinall -- grin $@ "${__USRLOG}" "${WORKON_HOME}/*/-usrlog.log" - source ${conf}/30-bashrc.usrlog.sh + source "${conf}/30-bashrc.usrlog.sh" # ## 30-bashrc.xlck.sh -- screensaver, (auto) lock, suspend # _setup_xlck() -- configure xlck - source ${conf}/30-bashrc.xlck.sh + source "${conf}/30-bashrc.xlck.sh" # ## 40-bashrc.aliases.sh -- aliases # _setup_venv_aliases() -- source in e, ew, makew, ssv, hgw, gitw # _setup_supervisord() -- configure _SVCFG # $1 (str): path to a supervisord.conf file "${1:-${_SVCFG}" - source ${conf}/40-bashrc.aliases.sh + source "${conf}/40-bashrc.aliases.sh" ## 42-bashrc.commands.sh -- example commands - source ${conf}/42-bashrc.commands.sh + source "${conf}/42-bashrc.commands.sh" # ## 50-bashrc.bashmarks.sh -- bashmarks: local bookmarks - source ${conf}/50-bashrc.bashmarks.sh + source "${conf}/50-bashrc.bashmarks.sh" # ## 70-bashrc.repos.sh -- repos: $__SRC repos, docs - source ${conf}/70-bashrc.repos.sh + source "${conf}/70-bashrc.repos.sh" # ## 99-bashrc.after.sh -- after: cleanup - source ${conf}/99-bashrc.after.sh + source "${conf}/99-bashrc.after.sh" } function dr { From 3c83cc5facb73ba52bb36d91c4be3573a81ea96d Mon Sep 17 00:00:00 2001 From: Wes Turner Date: Mon, 7 Sep 2015 00:24:42 -0500 Subject: [PATCH 04/12] ENH,DOC: xlck.sh: gnome-screensaver support, xlck_install, xlck_lock, usage --- scripts/xlck.sh | 108 +++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 89 insertions(+), 19 deletions(-) diff --git a/scripts/xlck.sh b/scripts/xlck.sh index 1aababd2..a945f5ab 100755 --- a/scripts/xlck.sh +++ b/scripts/xlck.sh @@ -3,9 +3,6 @@ ### xlck.sh -- script wrapper for xautolock, xlock, and/or i3lock ## as well as issuing suspend, shutdown, and restart commands -## Requirements: -# -# sudo apt-get install xautolock xlockmore i3lock function xlck { # xlck() -- xlck $@ @@ -18,8 +15,20 @@ function _xlck_install { # _xlck_install() -- install xlck dependencies # xlck requires: bash, pgrep, ps, kill, xautolock, xlock, i3lock, xset - sudo apt-get install bash procps x11-server-utils \ - xautolock xlockmore i3lock + function _xlck_install_apt { + sudo apt-get install -y bash procps x11-server-utils \ + xautolock xlockmore i3lock + } + function _xlck_install_yum { + local YUM="${1:-"yum"}" # yum, dnf + sudo $YUM install -y bash procps-ng xorg-x11-server-utils \ + xautolock xlockmore i3lock + } + + _xlck_install_apt + _xlck_install_yum + _xlck_install_yum "dnf" + ln -s ~/.dotfiles/etc/.xinitrc ~/.xinitrc } @@ -53,25 +62,64 @@ function _xlck_i3lock { # _xlck_i3lock() -- start i3lock with a dark gray background /usr/bin/i3lock -d -c 202020 } +function xlck_gnome_screensaver_status { + # xlck_gnome_screensaver_status() -- gnome-screensaver PIDs on $DISPLAY + xlck_pgrep_display "gnome-screensaver" "$DISPLAY" + return +} -function xlck_lock { - # xlock_lock() -- lock the current display - # note: this will be run before suspend to RAM and Disk. - #if [[ -x /usr/bin/gnome-screensaver-command ]]; then - # # TODO XXX: - # # if gnome-screensaver not running **in this display**, - # # gnome-screensaver &; disown - # gnome-screensaver-command -l +function xlck_gnome_screensaver_start { + # xlck_gnome_screensaver_start() -- start gnome-screensaver + xlck_gnome_screensaver_status + gnome-screensaver --display="$DISPLAY" + xlck_gnome_screensaver_status +} + +function xlck_gnome_screensaver_lock { + # xlck_gnome_screensaver_lock() -- lock gnome-screensaver + xlck_gnome_screensaver_status + gnome-screensaver-command --lock +} + + +function _xlck_which_lock { if [[ -x /usr/bin/i3lock ]]; then + echo "i3lock" _xlck_i3lock elif [[ -x /usr/bin/xlock ]]; then + echo "xlock" _xlck_xlock - else - echo "Found neither i3lock nor xlock" - return -1 + elif [[ -x /usr/bin/gnome-screensaver ]]; then + echo "gnome-screensaver" + xlck_gnome_screensaver_lock fi } +function xlck_lock { + # xlock_lock() -- lock the current display + # $1 {i3lock|i3, xlock|x, gnome-screensaver|gnome|g} + # note: this will be run before suspend to RAM and Disk. + local lockfn="${1:-"$(_xlck_which_lock)"}" + case $lockfn in + i3lock|i3) + _xlck_i3lock + return + ;; + xlock|x) + _xlck_xlock + return + ;; + gnome-screensaver|gnome|g) + xlck_gnome_screensaver_start + xlck_gnome_screensaver_lock + return + ;; + *) + echo "Found neither i3lock nor xlock" + return -1 + esac +} + function _suspend_to_ram { # _suspend_to_ram() -- echo mem > /sys/power/state sudo bash -c 'echo mem > /sys/power/state' @@ -151,6 +199,23 @@ function xlck_restart { xlck_start } + +function xlck_pgrep_display { + # xlck_pgrep_display()-- find xautolock on this display + procname="${1}" + display="${2:-$DISPLAY}" + if [ -z "${@}" ]; then + echo "usage: []" + return 2 + fi + pids=$(pgrep "$procname") + if [ -n "$pids" ]; then + ps eww -p ${pids} \ + | grep " DISPLAY=$display" \ + | awk '{ print $1 }' + fi +} + function xlck_xautolock_pgrep_display { # xlck_xautolock_pgrep_display()-- find xautolock on this display display=${1:-$DISPLAY} @@ -234,9 +299,9 @@ function _xlck_xautolock { function xlck_usage { echo "# $0" - echo "Usage: $(basename $0) < -I | -U | -S | -P | -R | -M | -N | -D | -L |-X >"; + echo "$(basename $0) [-h] [-I|-U|-S|-P|-R|-M|-N|-D|-L|-X]"; echo "" - echo " a script for working with xautolock, xlock, and/or i3lock;" + echo " a script for working with xautolock and xlock, i3lock;" echo " as well as issuing suspend, shutdown, and restart commands." echo "" echo " -I -- (I)nstall xlck (apt-get)" @@ -255,6 +320,11 @@ function xlck_usage { } function xlck_main { + if [ -z "${@}" ]; then + xlck_usage + # return nonzero if no args + return 86 + fi while getopts "USPRMDLXh" opt; do case "${opt}" in I) @@ -293,6 +363,6 @@ function xlck_main { if [[ "$BASH_SOURCE" == "$0" ]]; then _xlck_setup - xlck_main $@ + xlck_main "$@" exit fi From 065e72749d2f3877c09ce1463a4c63f887b5e0fe Mon Sep 17 00:00:00 2001 From: Wes Turner Date: Mon, 7 Sep 2015 01:23:25 -0500 Subject: [PATCH 05/12] ENH: scripts/setup_node.sh: #needstests --- scripts/setup_node.sh | 209 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 209 insertions(+) create mode 100755 scripts/setup_node.sh diff --git a/scripts/setup_node.sh b/scripts/setup_node.sh new file mode 100755 index 00000000..e70bfb50 --- /dev/null +++ b/scripts/setup_node.sh @@ -0,0 +1,209 @@ +#!/bin/sh +## setup_node.sh + +# see also: https://github.com/saltstack-formulas/node-formula/blob/master/node/map.jinja + +# TODO: +# - [ ] don't reset to default version when NODE_VERSION is unspecified +# - [ ] install npm + +# sudo node install -g node + +_filename="${0}" +__file__="$(basename "${_filename}")" + +NODE_VERSION=${NODE_VERSION:-"v0.12.7"} + +function setup_node_help { + echo "${__file__} -- install node from tar.gz, git, or with NVM" + echo "" + echo " Arguments" + echo " --install/-i -- install node (by default from tar.gz)" + echo ' $NODE_VERSION # (default: v0.12.7)' + echo " --git/--src -- install from source (requires -i)" + echo ' $NODE_VERSION # (default: v0.12.7)' + echo " --nvm -- install nvm and node w/ nvm (requires -i)" + echo ' $NVM_DIR # path to nvm (default: ~/.nvm)' + echo "" + echo " Usage:" + echo " ${__file__} -i" + echo " ${__file__} -i --git" + echo " ${__file__} -i --nvm" + echo " ${__file__} -i --nvm --git" + echo ' NVM_VERSION="master" '"${__file__}"' -i --nvm --git' + echo ' NVM_DIR="${__DOTFILES}/src/nvm" '"${__file__}"' -i --nvm --git' + echo "" + echo " NodeJS -- Node" + echo " Homepage: https://nodejs.org/" + echo " Download: https://nodejs.org/download/" + echo " Src: https://github.com/joyent/node" + echo " Docs: https://docs.nodejs.com/getting-started/installing-node" + echo " Docs: https://raw.githubusercontent.com/joyent/node/master/ChangeLog" + echo "" + echo " NPM -- Node Package Manager (now bundled with Node)" + echo " Homepage: https://npmjs.com/" + echo " Src: https://github.com/npm/npm" + echo " Docs: https://docs.npmjs.com/" + echo "" + echo " NVM -- Node Version Manager" + echo " Src: https://github.com/creationix/nvm" + echo "" +} + +function setup_node_dependencies__dnf { + dnf install -y gcc g++ python2 make +} + +function setup_node_dependencies__apt { + apt-get install -y gcc g++ python2 make +} + +function setup_node_download_node { + local version="${1:-"${NODE_VERSION}"}" + + local filename="node-${version}.tar.gz" + local url="https://nodejs.org/dist/${version}/${filename}" + curl -Ss "${url}" > "${filename}" + ls -al "${filename}" + #md5sum "${filename}" | #shasum "${filename}" + file "${filename}" + tar xzvf "${filename}" + cd "node-${version}" # TODO: +} + +function setup_node_node_gitclone_install { + local rev="${1}" + local url="https://github.com/joyent/node" + local dest="./node" + git clone "${url}" "${dest}" + cd "${dest}" + if [ -n "${rev}" ]; then + git checkout "${rev}" + fi +} + +function setup_node_install_node { + ./configure --prefix="${HOME}/.local" + ./configure --prefix="${HOME}/.local/node" + make + #make test + make install +} + + +## + +function setup_node_nvm_download_installsh { + #| Src: git https://github.com/creationix/nvm + local version="v0.25.4" + #local version="master" # TODO + local filename="install.sh" + local url="https://raw.githubusercontent.com/creationix/nvm/${version}/${install.sh}" + curl -Ss "${url}" > "${filename}" +} + +function setup_node_nvm_installsh_install { + local version="v0.25.4" + local filename="install.sh" + + if [ ! -f "${filename}" ]; then + setup_node_nvm_download_nvm "${version}" + fi + + #NVM_DIR="${HOME}/.nvm" # default + #NVM_DIR="${HOME}/.local/nvm" + bash ./install.sh + +} + +function setup_node_nvm_gitclone_install { + local NVM_DIR="${1:-"${HOME}/.nvm"}" # default + #local NVM_DIR="${HOME}/.local/nvm" + local NVM_GIT_URI="https://github.com/creationix/nvm" + + git clone "${NVM_GIT_URI}" "${NVM_DIR}" + cd "${NVM_DIR}" && git checkout $(git describe --abbrev=0 --tags) + echo "To use NVM, source nvm.sh into the current shell:" + echo "$ source ~/.nvm/nvm.sh" +} + + +function setup_node_nvm_install_and_use { + local node_verstr="${1:-"stable"}" + #node_verstr="unstable" + #node_verstr="v0.12.7" + _setup_nvm + nvm install "${node_verstr}" + nvm use "${node_verstr}" +} +# setup_node_nvm_install_and_use "stable" +#( nvm install stable; nvm use stable ) + +function _setup_nvm { + export NVM_DIR="${1:-"${HOME}/.nvm"}" # default + #local NVM_DIR="${__DOTFILES}/src/nvm" + local nvmsh="${NVM_DIR}/nvm.sh" + if [ ! -f "${nvmsh}" ]; then + echo "Err: Not found: ${nvmsh}" >&2 + echo "Err: You might try:" >&2 + echo "Err: setup_node.sh --install --nvm" >&2 + else + source "${nvmsh}" + fi +} + +## nn-bashrc.node.sh +# test -d ~/.nvm || echo +# configure anyway + + +function setup_node_main { + for arg in "${@}"; do + case "${arg}" in + -i|--install) + local __do_install=1 + ;; + --src|--git) + local __do_install_from_source=1; + ;; + --nvm) + local __do_install_with_nvm=1; + ;; + -h|--help) + local __do_help=1; + ;; + esac + done + + if [ -n "${__do_help}" ]; then + setup_node_help + exit + fi + + if [ -n "${__do_install}" ]; then + if [ -n "${__do_install_with_nvm}" ]; then + if [ -n "${__do_install_from_source}" ]; then + setup_node_nvm_gitclone_install + else + setup_node_nvm_installsh_install + fi + setup_node_nvm_install_and_use "${NODE_VERSION}" + else + setup_node_dependencies__apt + setup_node_dependencies__deb + if [ -n "${__do_install_from_source}" ]; then + setup_node_node_gitclone_install "${NODE_VERSION}" + else + setup_node_download_node "${NODE_VERSION}" + fi + setup_node_install_node + fi + fi +} + +if [ "${BASH_SOURCE}" == "${0}" ]; then + (setup_node_main "${@}") + exit +else + _setup_nvm +fi From a9b15cb01954b88286e6ee012d604dd9c7a9051d Mon Sep 17 00:00:00 2001 From: Wes Turner Date: Mon, 7 Sep 2015 01:26:09 -0500 Subject: [PATCH 06/12] DOC,SEC: scripts/whyquote.sh: shell quoting --- scripts/whyquote.sh | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 scripts/whyquote.sh diff --git a/scripts/whyquote.sh b/scripts/whyquote.sh new file mode 100644 index 00000000..a10a5364 --- /dev/null +++ b/scripts/whyquote.sh @@ -0,0 +1,24 @@ +#!/bin/sh -x + + +a="; echo '!$!'" + + +echo $a +echo ${a} +echo "$a" +echo "${a}" + + +echo "one" $a +echo "one" ${a} +echo "one" "$a" +echo "one" "${a}" + +# .. + +cmd="echo 'one'; ${a}" +echo ${cmd} +echo "${cmd}" +${cmd} +"${cmd}" From b901451ba9e62c3a7bb47a25e654c9519e355ffd Mon Sep 17 00:00:00 2001 From: Wes Turner Date: Sat, 12 Sep 2015 22:39:11 -0500 Subject: [PATCH 07/12] ENH,SEC: scripts/venv_relabel.sh: set virtualenv/venv fcontexts [semanage, restorecon] --- scripts/venv_relabel.sh | 45 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100755 scripts/venv_relabel.sh diff --git a/scripts/venv_relabel.sh b/scripts/venv_relabel.sh new file mode 100755 index 00000000..e9ce7c6e --- /dev/null +++ b/scripts/venv_relabel.sh @@ -0,0 +1,45 @@ +#!/bin/sh + +### venv_relabel.sh -- set virtualenv/venv fcontexts [semanage, restorecon] + +function _setlabels { + (set -x; + _path="${1}" # ${VIRTUAL_ENV}/tmp + _equalpth="${2}" # /tmp + _deleteexisting="${3:-${_VENV_RELABEL_DELETE_EXISTING}}" + if [ -n "${_deleteexisting}" ]; then + sudo semanage fcontext -D "${_path}"; + fi + sudo semanage fcontext --modify -e "${_equalpth}" "${_path}"; + sudo restorecon -Rv "${_path}"; + ls -alZd "${_path}") +} + +function venv_relabel { + + prefix="${1}" + if [ "${prefix}" == "" ]; then + echo "err" + fi + export _VENV_RELABEL_DELETE_EXISTING="${2:-"${_VENV_RELABEL_DELETE_EXISTING:-"true"}"}" + _setlabels "${prefix}/bin" "/usr/bin" + _setlabels "${prefix}/etc" "/usr/etc" + _setlabels "${prefix}/include" "/usr/include" + _setlabels "${prefix}/lib" "/usr/lib" + _setlabels "${prefix}/lib64" "/usr/lib" + _setlabels "${prefix}/man" "/usr/man" + _setlabels "${prefix}/share" "/usr/share" + _setlabels "${prefix}/tmp" "/usr/tmp" + _setlabels "${prefix}/var/cache" "/var/cache" + _setlabels "${prefix}/var/log" "/var/log" + _setlabels "${prefix}/var/run" "/var/run" + _setlabels "${prefix}/var/www" "/var/www" + + ls -alZ "${prefix}" +} + +function venv_relabel_main { + venv_relabel "${1}" +} + +venv_relabel_main "${1}" From e1d398afb3dad10d14ccb26ad337d22b5044e78b Mon Sep 17 00:00:00 2001 From: Wes Turner Date: Sat, 12 Sep 2015 22:39:51 -0500 Subject: [PATCH 08/12] BLD: Makefile: add shortrev to gh-pages commit msg --- Makefile | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 71ce7184..971dc9c6 100644 --- a/Makefile +++ b/Makefile @@ -635,7 +635,9 @@ sdist: clean gh-pages: # Push docs to gh-pages branch with a .nojekyll file - ghp-import -n -p ./docs/_build/html/ + ghp-import -n -p ./docs/_build/html/ \ + -m "DOC,RLS: gh-pages from: $(shell git -C $(shell pwd) rev-parse --short HEAD)" + pull: git pull From f5cff66a15fe7e219219f173073d8a4f600f68fd Mon Sep 17 00:00:00 2001 From: Wes Turner Date: Sun, 13 Sep 2015 14:17:12 -0500 Subject: [PATCH 09/12] CLN,SEC: usrlog.sh: script variable quoting --- scripts/usrlog.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/scripts/usrlog.sh b/scripts/usrlog.sh index fac1a70e..d5f5a172 100755 --- a/scripts/usrlog.sh +++ b/scripts/usrlog.sh @@ -248,11 +248,11 @@ function _usrlog_writecmd { if [ -n "$ZSH_VERSION" ]; then id 2>&1 > /dev/null - _cmd=$(fc -l -1 | sed -e $TERM_SED_STR) + _cmd=$(fc -l -1 | sed -e "${TERM_SED_STR}") elif [ -n "$BASH" ]; then - _cmd=$(history 1 | sed -e $TERM_SED_STR) + _cmd=$(history 1 | sed -e "${TERM_SED_STR}") else - _cmd=$(history 1 | sed -e $TERM_SED_STR) + _cmd=$(history 1 | sed -e "${TERM_SED_STR}") fi _usrlog_append "${_cmd}" } From 5aa39b76ef5493b08bc1eb36fc53ce6a319d4517 Mon Sep 17 00:00:00 2001 From: Wes Turner Date: Sun, 13 Sep 2015 14:21:00 -0500 Subject: [PATCH 10/12] BUG,SEC: scripts/venv_relabel.sh: ./lib64 symlink before ./lib, quoting #37 --- scripts/venv_relabel.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/scripts/venv_relabel.sh b/scripts/venv_relabel.sh index e9ce7c6e..c84c483a 100755 --- a/scripts/venv_relabel.sh +++ b/scripts/venv_relabel.sh @@ -25,8 +25,8 @@ function venv_relabel { _setlabels "${prefix}/bin" "/usr/bin" _setlabels "${prefix}/etc" "/usr/etc" _setlabels "${prefix}/include" "/usr/include" - _setlabels "${prefix}/lib" "/usr/lib" _setlabels "${prefix}/lib64" "/usr/lib" + _setlabels "${prefix}/lib" "/usr/lib" _setlabels "${prefix}/man" "/usr/man" _setlabels "${prefix}/share" "/usr/share" _setlabels "${prefix}/tmp" "/usr/tmp" @@ -39,7 +39,7 @@ function venv_relabel { } function venv_relabel_main { - venv_relabel "${1}" + venv_relabel "${1}" "${2:-"true"}" } -venv_relabel_main "${1}" +venv_relabel_main "${1}" "${2}" From 48274bd40cddb63f8580e942b4d168f932bbd0b4 Mon Sep 17 00:00:00 2001 From: Wes Turner Date: Sun, 13 Sep 2015 14:26:40 -0500 Subject: [PATCH 11/12] BUG,SEC: scripts/venv_relabel.sh: return -1 if prefix is unset #37 --- scripts/venv_relabel.sh | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/scripts/venv_relabel.sh b/scripts/venv_relabel.sh index c84c483a..26c4ac5c 100755 --- a/scripts/venv_relabel.sh +++ b/scripts/venv_relabel.sh @@ -12,15 +12,22 @@ function _setlabels { fi sudo semanage fcontext --modify -e "${_equalpth}" "${_path}"; sudo restorecon -Rv "${_path}"; - ls -alZd "${_path}") + ls -alZd "${_path}") + return } function venv_relabel { - prefix="${1}" + local prefix="${1}" if [ "${prefix}" == "" ]; then - echo "err" + echo "err: prefix must be specified" + return -1 fi + # .. note: this is destructive of any existing labels + # if _VENV_RELABEL_DELETE_EXISTING != "" (default: "true") + # if [ "${prefix}" == "/" ]; then + # prefix="" + # fi export _VENV_RELABEL_DELETE_EXISTING="${2:-"${_VENV_RELABEL_DELETE_EXISTING:-"true"}"}" _setlabels "${prefix}/bin" "/usr/bin" _setlabels "${prefix}/etc" "/usr/etc" @@ -36,10 +43,13 @@ function venv_relabel { _setlabels "${prefix}/var/www" "/var/www" ls -alZ "${prefix}" + return } function venv_relabel_main { venv_relabel "${1}" "${2:-"true"}" + return } venv_relabel_main "${1}" "${2}" +exit From 229511fe4dcf70c76662244d749fcafe79e7de6e Mon Sep 17 00:00:00 2001 From: Wes Turner Date: Sun, 13 Sep 2015 14:34:24 -0500 Subject: [PATCH 12/12] ENH: venv_relabel.sh: ls -aldZ "${prefix}"/* --- scripts/venv_relabel.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/venv_relabel.sh b/scripts/venv_relabel.sh index 26c4ac5c..e904defa 100755 --- a/scripts/venv_relabel.sh +++ b/scripts/venv_relabel.sh @@ -42,7 +42,7 @@ function venv_relabel { _setlabels "${prefix}/var/run" "/var/run" _setlabels "${prefix}/var/www" "/var/www" - ls -alZ "${prefix}" + (set -x; ls -aldZ "${prefix}"/*) return }