From 0a83ba995274535a36e790f8530583fdadfa9297 Mon Sep 17 00:00:00 2001 From: dctrud Date: Wed, 11 Jan 2023 11:51:02 +0000 Subject: [PATCH] General tidy --- .gitignore | 1 - bin/backup_inspiron.sh | 6 +- bin/backup_legion.sh | 6 +- bin/backup_mini.sh | 6 +- bin/dotfiles | 198 ++++------------ bin/ical2org.awk | 392 -------------------------------- bin/install-perl-tools.sh | 2 +- bin/install-python-tools.sh | 2 +- bin/isip | 26 --- bin/kxt | 5 - bin/lock | 13 -- bin/manh | 43 ---- bin/manp | 35 --- bin/mount_work.sh | 4 - bin/patchelf-guix | 5 - bin/pid | 23 -- bin/rename | 310 ------------------------- bin/resample-dpi | 38 ---- bin/shuffle-all | 5 - bin/ssid | 26 --- bin/sync-web.sh | 3 - bin/tar-subdirs.sh | 7 - bin/wake-gwinear.sh | 4 - bin/wake-ythel.sh | 3 - conf/manh/styles.css | 37 --- copy/.gitconfig | 3 - init/20_osx_homebrew.sh | 2 +- init/30_osx_homebrew_casks.sh | 2 - init/30_osx_homebrew_recipes.sh | 1 - link/.vim/autoload/plug.vim | 28 ++- link/.vim/autoload/plug.vim.old | 2 +- link/.vimrc | 1 - source/00_dotfiles.sh | 4 +- source/10_user_bin.sh | 2 + source/50_anaconda.sh | 10 +- source/50_editor.sh | 4 +- source/50_file.sh | 11 +- source/50_go.sh | 2 + source/50_gpg.sh | 5 +- source/50_keychain.sh | 6 +- source/50_misc.sh | 6 +- source/50_npm.sh | 2 + source/50_perl5.sh | 2 + source/50_prompt.sh | 4 +- source/50_pyenv.sh | 2 +- source/50_rbenv.sh | 2 +- source/50_remote.sh | 5 +- source/50_singularity.sh | 2 + vendor/rename/README.txt | 6 - vendor/rename/rename | 310 ------------------------- 50 files changed, 118 insertions(+), 1506 deletions(-) delete mode 100755 bin/ical2org.awk delete mode 100755 bin/isip delete mode 100755 bin/kxt delete mode 100755 bin/lock delete mode 100755 bin/manh delete mode 100755 bin/manp delete mode 100644 bin/mount_work.sh delete mode 100755 bin/patchelf-guix delete mode 100755 bin/pid delete mode 100755 bin/rename delete mode 100755 bin/resample-dpi delete mode 100755 bin/shuffle-all delete mode 100755 bin/ssid delete mode 100755 bin/sync-web.sh delete mode 100755 bin/tar-subdirs.sh delete mode 100755 bin/wake-gwinear.sh delete mode 100755 bin/wake-ythel.sh delete mode 100644 conf/manh/styles.css delete mode 100644 vendor/rename/README.txt delete mode 100644 vendor/rename/rename diff --git a/.gitignore b/.gitignore index dc470f1..1dccb17 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,5 @@ # Lots of junk goes in here. /caches/ -/backups/ # Top secret stuff! /link/.ssh/authorized_keys diff --git a/bin/backup_inspiron.sh b/bin/backup_inspiron.sh index 8ea2f8c..b67aa2a 100755 --- a/bin/backup_inspiron.sh +++ b/bin/backup_inspiron.sh @@ -1,15 +1,15 @@ #!/usr/bin/env bash HOST="inspiron" DEST="de1103@de1103.rsync.net:borg_${HOST}" -SOURCES="/home /data/Shared/Shared_Documents /data/Shared/Shared_Software" +SOURCES=("/home" "/data/Shared/Shared_Documents" "/data/Shared/Shared_Software") -if [ $(hostname -s) != "${HOST}" ]; then +if [ "$(hostname -s)" != "${HOST}" ]; then echo "Must be run from ${HOST}" exit 255 fi echo "Backup to ${DEST}" -sudo borg create --remote-path=borg1 -s --progress "${DEST}::$(date '+%Y%m%d-%H%M')" ${SOURCES} +sudo borg create --remote-path=borg1 -s --progress "${DEST}::$(date '+%Y%m%d-%H%M')" "${SOURCES[@]}" echo echo DONE diff --git a/bin/backup_legion.sh b/bin/backup_legion.sh index 378fb09..2fadc37 100755 --- a/bin/backup_legion.sh +++ b/bin/backup_legion.sh @@ -1,15 +1,15 @@ #!/usr/bin/env bash HOST="LEGION" DEST="dctrud@piran:/usb/borg/borg_${HOST}" -SOURCES="/home /mnt/d/Ben /mnt/d/Dave /mnt/d/Dona /mnt/d/Shared /mnt/d/Thomas" +SOURCES=("/home" "/mnt/d/Ben" "/mnt/d/Dave" "/mnt/d/Dona" "/mnt/d/Shared" "/mnt/d/Thomas") -if [ $(hostname -s) != "${HOST}" ]; then +if [ "$(hostname -s)" != "${HOST}" ]; then echo "Must be run from ${HOST}" exit 255 fi echo "Backup to ${DEST}" -sudo borg create -s --progress "${DEST}::$(date '+%Y%m%d-%H%M')" ${SOURCES} +sudo borg create -s --progress "${DEST}::$(date '+%Y%m%d-%H%M')" "${SOURCES[@]}" echo echo DONE diff --git a/bin/backup_mini.sh b/bin/backup_mini.sh index c43fa3d..6858415 100755 --- a/bin/backup_mini.sh +++ b/bin/backup_mini.sh @@ -1,15 +1,15 @@ #!/usr/bin/env bash HOST="mini" DEST="dctrud@piran:/usb/borg/borg_${HOST}" -SOURCES="/home /etc /var /data" +SOURCES=("/home" "/etc" "/var" /"data") -if [ $(hostname -s) != "${HOST}" ]; then +if [ "$(hostname -s)" != "${HOST}" ]; then echo "Must be run from ${HOST}" exit 255 fi echo "Backup to ${DEST}" -sudo borg create -s --progress "${DEST}::$(date '+%Y%m%d-%H%M')" ${SOURCES} +sudo borg create -s --progress "${DEST}::$(date '+%Y%m%d-%H%M')" "${SOURCES[@]}" echo echo DONE diff --git a/bin/dotfiles b/bin/dotfiles index 96a33a4..9f4724d 100755 --- a/bin/dotfiles +++ b/bin/dotfiles @@ -1,7 +1,10 @@ #!/usr/bin/env bash -[[ "$1" == "source" ]] || \ - -echo 'Dotfiles - "Cowboy" Ben Alman - http://benalman.com/' +if [[ "$1" != "source" ]]; then + echo "dctrud's dotfiles" + echo + echo "Adapted from:" + echo ' Dotfiles - "Cowboy" Ben Alman - http://benalman.com/' +fi if [[ "$1" == "-h" || "$1" == "--help" ]]; then cat </dev/null)" == dotfiles ]] || return 1 + [[ $(basename "$0" 2>/dev/null) == dotfiles ]] || return 1 } # OS detection +function is_linux() { + [[ "$OSTYPE" =~ ^linux ]] || return 1 +} function is_osx() { [[ "$OSTYPE" =~ ^darwin ]] || return 1 } -function is_ubuntu() { - [[ "$(cat /etc/issue 2> /dev/null)" =~ Ubuntu ]] || return 1 -} -function is_ubuntu_desktop() { - dpkg -l ubuntu-desktop >/dev/null 2>&1 || return 1 -} function get_os() { - for os in osx ubuntu ubuntu_desktop; do - is_$os; [[ $? == ${1:-0} ]] && echo $os + for os in linux osx; do + is_$os; [[ $? == "${1:-0}" ]] && echo $os done } @@ -89,18 +89,18 @@ function path_remove() { # Display a fancy multi-select menu. # Inspired by http://serverfault.com/a/298312 function prompt_menu() { - local exitcode prompt choices nums i n + local exitcode prompt nums i n exitcode=0 if [[ "$2" ]]; then _prompt_menu_draws "$1" - read -t $2 -n 1 -sp "Press ENTER or wait $2 seconds to continue, or press any other key to edit." + read -r -t "$2" -n 1 -sp "Press ENTER or wait $2 seconds to continue, or press any other key to edit." exitcode=$? echo "" fi 1>&2 if [[ "$exitcode" == 0 && "$REPLY" ]]; then prompt="Toggle options (Separate options with spaces, ENTER when done): " while _prompt_menu_draws "$1" 1 && read -rp "$prompt" nums && [[ "$nums" ]]; do - _prompt_menu_adds $nums + _prompt_menu_adds "$nums" done fi 1>&2 _prompt_menu_adds @@ -114,7 +114,7 @@ function _prompt_menu_iter() { for sel in "${menu_selects[@]}"; do [[ "$sel" == "${menu_options[i]}" ]] && state=1 && break done - $fn $state $i "$@" + $fn $state "$i" "$@" done } @@ -126,9 +126,9 @@ function _prompt_menu_draws() { function _prompt_menu_draw() { local modes=(error success) if [[ "$3" ]]; then - e_${modes[$1]} "$(printf "%2d) %s\n" $(($2+1)) "${menu_options[$2]}")" + e_"${modes[$1]}" "$(printf "%2d) %s\n" $(($2+1)) "${menu_options[$2]}")" else - e_${modes[$1]} "${menu_options[$2]}" + e_"${modes[$1]}" "${menu_options[$2]}" fi } @@ -157,10 +157,10 @@ function _prompt_menu_add() { # Usage: array_map array_name [map_fn] function array_map() { local __i__ __val__ __arr__=$1; shift - for __i__ in $(eval echo "\${!$__arr__[@]}"); do - __val__="$(eval echo "\"\${$__arr__[__i__]}\"")" + for __i__ in $(eval echo "\${!${__arr__[*]}}"); do + __val__="$(eval echo "\"\${${__arr__[__i__]}}\"")" if [[ "$1" ]]; then - "$@" "$__val__" $__i__ + "$@" "$__val__" "$__i__" else echo "$__val__" fi @@ -168,7 +168,7 @@ function array_map() { } # Print bash array in the format "i " (one per line) for debugging. -function array_print() { array_map $1 __array_print; } +function array_print() { array_map "$1" __array_print; } function __array_print() { echo "$2 <$1>"; } # Array filter. Calls filter_fn for each item ($1) and index ($2) in array_name @@ -184,18 +184,18 @@ function array_filter_i() { __array_filter 0 "$@"; } function __array_filter() { local __i__ __val__ __mode__ __arr__ __mode__=$1; shift; __arr__=$1; shift - for __i__ in $(eval echo "\${!$__arr__[@]}"); do - __val__="$(eval echo "\${$__arr__[__i__]}")" + for __i__ in $(eval echo "\${!${__arr__[*]}}"); do + __val__="$(eval echo "\${${__arr__[__i__]}}")" if [[ "$1" ]]; then - "$@" "$__val__" $__i__ >/dev/null + "$@" "$__val__" "$__i__" >/dev/null else [[ "$__val__" ]] fi if [[ "$?" == 0 ]]; then if [[ $__mode__ == 1 ]]; then - eval echo "\"\${$__arr__[__i__]}\"" + eval echo "\"\${${__arr__[__i__]}}\"" else - echo $__i__ + echo "$__i__" fi fi done @@ -209,10 +209,10 @@ function array_join_filter() { __array_join 0 "$@"; } function __array_join() { local __i__ __val__ __out__ __init__ __mode__ __arr__ __mode__=$1; shift; __arr__=$1; shift - for __i__ in $(eval echo "\${!$__arr__[@]}"); do - __val__="$(eval echo "\"\${$__arr__[__i__]}\"")" + for __i__ in $(eval echo "\${!${__arr__[*]}}"); do + __val__="$(eval echo "\"\${${__arr__[__i__]}}\"")" if [[ $__mode__ == 1 || "$__val__" ]]; then - [[ "$__init__" ]] && __out__="$__out__$@" + [[ "$__init__" ]] && __out__="$__out__$*" __out__="$__out__$__val__" __init__=1 fi @@ -241,7 +241,7 @@ function setdiff() { if [[ "$1" == 1 ]]; then debug=1; shift; fi if [[ "$1" ]]; then local setdiff_new setdiff_cur setdiff_out - setdiff_new=($1); setdiff_cur=($2) + setdiff_new=("$1"); setdiff_cur=("$2") fi setdiff_out=() for a in "${setdiff_new[@]}"; do @@ -252,7 +252,7 @@ function setdiff() { [[ "$skip" ]] || setdiff_out=("${setdiff_out[@]}" "$a") done [[ "$debug" ]] && for a in setdiff_new setdiff_cur setdiff_out; do - echo "$a ($(eval echo "\${#$a[*]}")) $(eval echo "\${$a[*]}")" 1>&2 + echo "$a ($(eval echo "\${#${a[*]}}")) $(eval echo "\${${a[*]}}")" 1>&2 done [[ "$1" ]] && echo "${setdiff_out[@]}" } @@ -293,7 +293,7 @@ function init_files() { [[ "$remove" ]] || menu_selects=("${menu_selects[@]}" "$opt") done fi - prompt_menu "Run the following init scripts?" $prompt_delay + prompt_menu "Run the following init scripts?" "$prompt_delay" # Write out cache file for future reading. rm "$init_file" 2>/dev/null for i in "${!menu_selects[@]}"; do @@ -327,7 +327,7 @@ function link_test() { } function link_do() { e_success "Linking ~/$1." - ln -sf ${2#$HOME/} ~/ + ln -sf "${2#"$HOME"/}" ~/ } # Link config files. @@ -340,21 +340,21 @@ function config_test() { } function config_do() { e_success "Linking ~/.config/$1." - ln -sf ../${2#$HOME/} ~/.config/ + ln -sf ../"${2#"$HOME"/}" ~/.config/ } # Copy, link, init, etc. function do_stuff() { local base dest skip - local files=($DOTFILES/$1/*) - [[ $(declare -f "$1_files") ]] && files=($($1_files "${files[@]}")) + local files=("$DOTFILES"/"$1"/*) + [[ $(declare -f "$1_files") ]] && files=($("$1_files" "${files[@]}")) # No files? abort. if (( ${#files[@]} == 0 )); then return; fi # Run _header function only if declared. [[ $(declare -f "$1_header") ]] && "$1_header" # Iterate over files. for file in "${files[@]}"; do - base="$(basename $file)" + base="$(basename "$file")" # Get dest path. if [[ $(declare -f "$1_dest") ]]; then dest="$("$1_dest" "$base")" @@ -369,16 +369,6 @@ function do_stuff() { e_error "Skipping ~/$base, $skip." continue fi - # Destination file already exists in ~/. Back it up! - if [[ -e "$dest" ]]; then - e_arrow "Backing up ~/$base." - # Set backup flag, so a nice message can be shown at the end. - backup=1 - # Create backup dir if it doesn't already exist. - [[ -e "$backup_dir" ]] || mkdir -p "$backup_dir" - # Backup file / link / whatever. - mv "$dest" "$backup_dir" - fi fi # Do stuff. "$1_do" "$base" "$file" @@ -390,109 +380,18 @@ function do_stuff() { # Set the prompt delay to be longer for the very first run. export prompt_delay=5; is_dotfiles_bin || prompt_delay=15 -# Keep-alive: update existing sudo time stamp if set, otherwise do nothing. -# Note that this doesn't work with Homebrew, since brew explicitly invalidates -# the sudo timestamp, which is probably wise. -# See https://gist.github.com/cowboy/3118588 -while true; do sudo -n true; sleep 10; kill -0 "$$" || exit; done 2>/dev/null & - -# Install a custom sudoers file that allows "sudo apt-get" to be executed -# without asking for a password. -sudoers_file=/etc/sudoers.d/cowboy-dotfiles -# Contents of the sudoers file. -function sudoers_text() { - cat < $sudoers_file -chmod 0440 $sudoers_file -if visudo -c; then - echo; echo "Sudoers file created." -else - rm $sudoers_file - echo; echo "Unable to create sudoers file." -fi -EOF -} -# Offer to create the sudoers file if it doesn't exist. -if is_ubuntu && [[ ! -e $sudoers_file ]]; then - cat < orgmodeentries.org -# -# Note: change org meta information generated below for author and -# email entries! -# -# Caveats: -# -# - date entries with no time specified are assumed to be local time zone; -# same remark for date entries that do have a time but do not end with Z -# e.g.: 20130101T123456 is local and will be kept as 2013-01-01 12:34 -# where 20130223T123422Z is UTC and will be corrected appropriately -# -# - UTC times are changed into local times, using the time zone of the -# computer that runs the script; it would be very hard in an awk script -# to respect the time zone of a file belonging to another time zone: -# the offsets will be different as well as the switchover time(s); -# (consider a remote shell to a computer with the file's time zone) -# -# - the UTC conversion entirely relies on the built-in strftime method; -# the author is not responsible for any erroneous conversions nor the -# consequence of such conversions -# -# - does process RRULE recurring events, but ignores COUNT specifiers -# -# - does not process EXDATE to exclude date(s) from recurring events -# -# Eric S Fraga -# 20100629 - initial version -# 20100708 - added end times to timed events -# - adjust times according to time zone information -# - fixed incorrect transfer for entries with ":" embedded within the text -# - added support for multi-line summary entries (which become headlines) -# 20100709 - incorporated time zone identification -# - fixed processing of continuation lines as Google seems to -# have changed, in the last day, the number of spaces at -# the start of the line for each continuation... -# - remove backslashes used to protect commas in iCal text entries -# no further revision log after this as the file was moved into a git -# repository... -# -# Updated by: Guido Van Hoecke -# Last change: 2013.05.26 14:28:33 -#---------------------------------------------------------------------------------- - -BEGIN { - ### config section - - # maximum age in days for entries to be output: set this to -1 to - # get all entries or to N>0 to only get enties that start or end - # less than N days ago - max_age = 7; - - # set to 1 or 0 to yes or not output a header block with TITLE, - # AUTHOR, EMAIL etc... - header = 1; - - # set to 1 or 0 to yes or not output the original ical preamble as - # comment - preamble = 1; - - # set to 1 to output time and summary as one line starting with - # the time (value 1) or to 0 to output the summary as first line - # and the date and time info as a second line - condense = 0; - - # set to 1 or 0 to yes or not output the original ical entry as a - # comment (mostly useful for debugging purposes) - original = 1; - - # google truncates long subjects with ... which is misleading in - # an org file: it gives the unfortunate impression that an - # expanded entry is still collapsed; value 1 will trim those - # ... and value 0 doesn't touch them - trimdots = 1; - - # change this to your name - author = "Eric S Fraga" - - # and to your email address - emailaddress = "e.fraga@ucl.ac.uk" - - ### end config section - - # use a colon to separate the type of data line from the actual contents - FS = ":"; - - # we only need to preserve the original entry lines if either the - # preamble or original options are true - preserve = preamble || original - first = 1; # true until an event has been found - max_age_seconds = max_age*24*60*60 - - if (header) { - print "#+TITLE: Main Google calendar entries" - print "#+AUTHOR: ", author - print "#+EMAIL: ", emailaddress - print "#+DESCRIPTION: converted using the ical2org awk script" - print "#+CATEGORY: google" - print "#+STARTUP: hidestars" - print "#+STARTUP: overview" - print "" - } -} - -# continuation lines (at least from Google) start with a space -# if the continuation is after a description or a summary, append the entry -# to the respective variable - -/^[ ]/ { - if (indescription) { - entry = entry gensub("\r", "", "g", gensub("^[ ]", "", "", $0)); - } else if (insummary) { - summary = summary gensub("\r", "", "g", gensub("^[ ]", "", "", $0)) - } - if (preserve) - icalentry = icalentry "\n" $0 -} - -/^BEGIN:VEVENT/ { - # start of an event: initialize global velues used for each event - date = ""; - entry = "" - headline = "" - icalentry = "" # the full entry for inspection - id = "" - indescription = 0; - insummary = 0 - intfreq = "" # the interval and frequency for repeating org timestamps - lasttimestamp = -1; - location = "" - rrend = "" - status = "" - summary = "" - - # if this is the first event, output the preamble from the iCal file - if (first) { - if(preamble) { - print "* COMMENT original iCal preamble" - print gensub("\r", "", "g", icalentry) - } - if (preserve) - icalentry = "" - first = false; - } -} - -# any line that starts at the left with a non-space character is a new data field - -/^[A-Z]/ { - # we do not copy DTSTAMP lines as they change every time you download - # the iCal format file which leads to a change in the converted - # org file as I output the original input. This change, which is - # really content free, makes a revision control system update the - # repository and confuses. - if (preserve) - if (! index("DTSTAMP", $1)) - icalentry = icalentry "\n" $0 - # this line terminates the collection of description and summary entries - indescription = 0; - insummary = 0; -} - -# this type of entry represents a day entry, not timed, with date stamp YYYYMMDD - -/^DTSTART;VALUE=DATE/ { - date = datestring($2); -} - -/^DTEND;VALUE=DATE/ { - time2 = datestring($2, 1); - if ( issameday ) - time2 = "" -} - -# this represents a timed entry with date and time stamp YYYYMMDDTHHMMSS -# we ignore the seconds - -/^DTSTART[:;][^V]/ { - date = datetimestring($2); - # print date; -} - -# and the same for the end date; - -/^DTEND[:;][^V]/ { - time2 = datetimestring($2); - if (substr(date,1,10) == substr(time2,1,10)) { - # timespan within same date, use one date with a time range - date = date "-" substr(time2, length(time2)-4) - time2 = "" - } -} - -# repetition rule - -/^RRULE:FREQ=(DAILY|WEEKLY|MONTHLY|YEARLY)/ { - # get the d, w, m or y value - freq = tolower(gensub(/.*FREQ=(.).*/, "\\1", $0)) - # get the interval, and use 1 if none specified - interval = $2 ~ /INTERVAL=/ ? gensub(/.*INTERVAL=([0-9]+);.*/, "\\1", $2) : 1 - # get the enddate of the rule and use "" if none specified - rrend = $2 ~ /UNTIL=/ ? datestring(gensub(/.*UNTIL=([0-9]{8}).*/, "\\1", $2)) : "" - # build the repetitor vale as understood by org - intfreq = " +" interval freq - # if the repetition is daily, and there is an end date, drop the repetitor - # as that is the default - if (intfreq == " +1d" && time2 =="" && rrend != "") - intfreq = "" -} - -# The description will the contents of the entry in org-mode. -# this line may be continued. - -/^DESCRIPTION/ { - $1 = ""; - entry = entry gensub("\r", "", "g", $0); - indescription = 1; -} - -# the summary will be the org heading - -/^SUMMARY/ { - $1 = ""; - summary = gensub("\r", "", "g", $0); - - # trim trailing dots if requested by config option - if(trimdots && summary ~ /\.\.\.$/) - sub(/\.\.\.$/, "", summary) - insummary = 1; -} - -# the unique ID will be stored as a property of the entry - -/^UID/ { - id = gensub("\r", "", "g", $2); -} - -/^LOCATION/ { - location = gensub("\r", "", "g", $2); -} - -/^STATUS/ { - status = gensub("\r", "", "g", $2); -} - -# when we reach the end of the event line, we output everything we -# have collected so far, creating a top level org headline with the -# date/time stamp, unique ID property and the contents, if any - -/^END:VEVENT/ { - #output event - if(max_age<0 || ( lasttimestamp>0 && systime()--<" time2 - else if (rrend != "") - date = date ">--<" rrend - - # translate \n sequences to actual newlines and unprotect commas (,) - if (condense) - print "* <" date "> " gensub("^[ ]+", "", "", gensub("\\\\,", ",", "g", gensub("\\\\n", " ", "g", summary))) - else - print "* " gensub("^[ ]+", "", "", gensub("\\\\,", ",", "g", gensub("\\\\n", " ", "g", summary))) - print ":PROPERTIES:" - print ":ID: " id - if(length(location)) - print ":LOCATION: " location - if(length(status)) - print ":STATUS: " status - print ":END:" - if (! condense) - print "<" date ">" - print "" - # translate \n sequences to actual newlines and unprotect commas (,) - if(length(entry)>1) - print gensub("^[ ]+", "", "", gensub("\\\\,", ",", "g", gensub("\\\\n", "\n", "g", entry))); - - # output original entry if requested by 'original' config option - if (original) - print "** COMMENT original iCal entry\n", gensub("\r", "", "g", icalentry) - } -} - - - -# funtion to convert an iCal time string 'yyyymmddThhmmss[Z]' into a -# date time string as used by org, preferably including the short day -# of week: 'yyyy-mm-dd day hh:mm' or 'yyyy-mm-dd hh:mm' if we cannot -# define the day of the week - -function datetimestring(input) -{ - # print "________" - # print "input : " input - # convert the iCal Date+Time entry to a format that mktime can understand - spec = gensub("([0-9][0-9][0-9][0-9])([0-9][0-9])([0-9][0-9])T([0-9][0-9])([0-9][0-9])([0-9][0-9]).*[\r]*", "\\1 \\2 \\3 \\4 \\5 \\6", "g", input); - # print "spec :" spec - - stamp = mktime(spec); - lasttimestamp = stamp; - - if (stamp <= 0) { - # this is a date before the start of the epoch, so we cannot - # use strftime and will deliver a 'yyyy-mm-dd hh:mm' string - # without day of week; this assumes local time, and does not - # attempt UTC offset correction - spec = gensub("([0-9][0-9][0-9][0-9])([0-9][0-9])([0-9][0-9])T([0-9][0-9])([0-9][0-9])([0-9][0-9]).*[\r]*", "\\1-\\2-\\3 \\4:\\5", "g", input); - # print "==> spec:" spec; - return spec; - } - - if (input ~ /[0-9]{8}T[0-9]{6}Z/ ) { - # this is an utc time; - # we need to correct the timestamp by the utc offset for this time - offset = strftime("%z", stamp) - pm = substr(offset,1,1) 1 # define multiplier +1 or -1 - hh = substr(offset,2,2) * 3600 * pm - mm = substr(offset,4,2) * 60 * pm - - # adjust the timestamp - stamp = stamp + hh + mm - } - - return strftime("%Y-%m-%d %a %H:%M", stamp); -} - -# function to convert an iCal date into an org date; -# the optional parameter indicates whether this is an end date; -# for single or multiple whole day events, the end date given by -# iCal is the date of the first day after the event; -# if the optional 'isenddate' parameter is non zero, this function -# tries to reduce the given date by one day - -function datestring(input, isenddate) -{ - #convert the iCal string to a an mktime input string - spec = gensub("([0-9][0-9][0-9][0-9])([0-9][0-9])([0-9][0-9]).*[\r]*", "\\1 \\2 \\3 00 00 00", "g", input); - - # compute the nr of seconds after or before the epoch - # dates before the epoch will have a negative timestamp - # days after the epoch will have a positive timestamp - stamp = mktime(spec); - - if (isenddate) { - # subtract 1 day from the timestamp - # note that this also works for dates before the epoch - stamp = stamp - 86400; - - # register whether the end date is same as the start date - issameday = lasttimestamp == stamp - } - # save timestamp to allow for check of max_age - lasttimestamp = stamp - - if (stamp < 0) { - # this date is before the epoch; - # the returned datestring will not have the short day of week string - # as strftime does not handle negative times; - # we have to construct the datestring directly from the input - if (isenddate) { - # we really should return the date before the input date, but strftime - # does not work with negative timestamp values; so we can not use it - # to obtain the string representation of the corrected timestamp; - # we have to return the date specified in the iCal input and we - # add time 00:00 to clarify this - return spec = gensub("([0-9][0-9][0-9][0-9])([0-9][0-9])([0-9][0-9]).*[\r]*", "\\1-\\2-\\3 00:00", "g", input); - } else { - # just generate the desired representation of the input date, without time; - return gensub("([0-9][0-9][0-9][0-9])([0-9][0-9])([0-9][0-9]).*[\r]*", "\\1-\\2-\\3", "g", input); - } - } - - # return the date and day of week - return strftime("%Y-%m-%d %a", stamp); -} - -# Local Variables: -# time-stamp-line-limit: 1000 -# time-stamp-format: "%04y.%02m.%02d %02H:%02M:%02S" -# time-stamp-active: t -# time-stamp-start: "Last change:[ \t]+" -# time-stamp-end: "$" -# End: diff --git a/bin/install-perl-tools.sh b/bin/install-perl-tools.sh index bf5f7f3..f65653d 100755 --- a/bin/install-perl-tools.sh +++ b/bin/install-perl-tools.sh @@ -4,6 +4,6 @@ wget -O "${HOME}/bin/cpanm" https://cpanmin.us/ chmod +x "${HOME}/bin/cpanm" # Bootstrap local lib -cpanm -n --local-lib=~/perl5 local::lib && eval $(perl -I ~/perl5/lib/perl5/ -Mlocal::lib) +cpanm -n --local-lib=~/perl5 local::lib && eval "$(perl -I ~/perl5/lib/perl5/ -Mlocal::lib)" # Linting / tidy cpanm -n --local-lib=~/perl5 Perl::Critic Perl::Tidy diff --git a/bin/install-python-tools.sh b/bin/install-python-tools.sh index 6e87a23..38853e0 100755 --- a/bin/install-python-tools.sh +++ b/bin/install-python-tools.sh @@ -5,7 +5,7 @@ python3 /tmp/get-pip.py --user # Environment management pip install --user virtualenv pipenv # Language Server Protocol -pip install --user python-language-server[all] +pip install --user "python-language-server[all]" # Linters pip install --user flake8 pylint yamllint yamlfmt # Formatting diff --git a/bin/isip b/bin/isip deleted file mode 100755 index 692cd44..0000000 --- a/bin/isip +++ /dev/null @@ -1,26 +0,0 @@ -#!/usr/bin/env bash - -if [[ "$1" == "-h" || "$1" == "--help" ]]; then cat </dev/null && cat > "$file" < - - - -$(man "$@" 2>/dev/null | man2html -bare -nodepage) - - -EOF - -# Open HTML (if it does exist). -[[ -e "$file" ]] && open "$file" diff --git a/bin/manp b/bin/manp deleted file mode 100755 index 8377578..0000000 --- a/bin/manp +++ /dev/null @@ -1,35 +0,0 @@ -#!/usr/bin/env bash - -if [[ "$1" == "-h" || "$1" == "--help" ]]; then cat </dev/null 2>&1 - -# Open PDF (if it does exist). -[[ -e "$file" ]] && open "$file" diff --git a/bin/mount_work.sh b/bin/mount_work.sh deleted file mode 100644 index 84792ed..0000000 --- a/bin/mount_work.sh +++ /dev/null @@ -1,4 +0,0 @@ -#!/bin/sh - -sudo mount -t cifs -o user=dtrudg,uid=1000,gid=1001 //192.168.1.210/USB_SSD /mnt/USB_SSD -sudo mount -t cifs -o user=dtrudg,uid=1000,gid=1001 //192.168.1.210/USB_SSD /mnt/dtrudg diff --git a/bin/patchelf-guix b/bin/patchelf-guix deleted file mode 100755 index 5c88972..0000000 --- a/bin/patchelf-guix +++ /dev/null @@ -1,5 +0,0 @@ -#!/bin/sh - -INTERPRETER=$(patchelf --print-interpreter /bin/sh) -patchelf --set-interpreter "${INTERPRETER}" $1 - diff --git a/bin/pid b/bin/pid deleted file mode 100755 index 4af4155..0000000 --- a/bin/pid +++ /dev/null @@ -1,23 +0,0 @@ -#!/usr/bin/env bash - -if [[ "$1" == "-h" || "$1" == "--help" ]]; then cat < -S> - -F -S> - -F -S> -S> -S> -S> -S> -S> -S> -S> -S> -S> -S> - -=head1 DESCRIPTION - -C renames the filenames supplied according to the rules specified. If a given filename is not modified, it will not be renamed. If no filenames are given on the command line, filenames will be read via standard input. - -For example, to rename all files matching C<*.bak> to strip the extension, you might say - - rename 's/\.bak$//' *.bak - -If are confident that none of the filenames has C<.bak> anywhere else than at the end, you can also use the much easier typed - - rename -s .bak '' *.bak - -You can always do multiple changes in one ago: - - rename -s .tgz .tar.gz -s .tbz2 .tar.bz2 *.tar.* - -Note however that expressive options are order sensitive. The following would probably surprise you: - - rename -s foo bar -s bar baz * - -Since operations are cumulative, this would end up substituting (some of) the F matches in filenames with F! So pay attention to order. You may want to request a verbose dry run with C<-nv> for the first stab at a complex rename operation. - - rename -nv -s bar baz -s foo bar * - -You can combine the various expressive options to suit your needs. F.ex files from Microsoft(tm) Windows systems often have blanks and (sometimes nothing but) capital letters in their names. Let's say you have a bunch of such files to clean up, and you also want to move them to subdirectories based on extension. The following command should help, provided all directories already exist: - - rename -cz -e '$_ = "$1/$_" if /(\..*)\z/' * - -Again you need to pay attention to order sensitivity for expressive options. If you placed the C<-c> after the C<-e> in the above example, files with F<.zip> and F<.ZIP> extensions would be (attempted to be) moved to different directories because the directory name prefix would be added before the filenames were normalized. Once again, use verbose dry run requested using C<-nv> to get an idea of what exactly a complex rename operation is going to do. - -=head1 ARGUMENTS - -=over 4 - -=item B<-h>, B<--help> - -See a synopsis. - -=item B<--man> - -Browse the manpage. - -=back - -=head1 OPTIONS - -=over 4 - -=item B<-0>, B<--null> - -When reading file names from C, split on NUL bytes instead of newlines. This is useful in combination with GNU find's C<-print0> option, GNU grep's C<-Z> option, and GNU sort's C<-z> option, to name just a few. B - -=item B<-c>, B<--lower-case> - -Converts file names to all lower case. - -=item B<-C>, B<--upper-case> - -Converts file names to all upper case. - -=item B<-e>, B<--expr> - -The C argument to this option should be a Perl expression that assumes the filename in the C<$_> variable and modifies it for the filenames to be renamed. When no other C<-c>, C<-C>, C<-e>, C<-s>, or C<-z> options are given, you can omit the C<-e> from infront of the code. - -=item B<-g>, B<--glob> - -Glob filename arguments. This is useful if you're using a braindead shell such as F which won't expand wildcards on behalf of the user. - -=item B<-f>, B<--force> - -Rename even when a file with the destination name already exists. - -=item B<-i>, B<--interactive> - -Ask the user to confirm every action before it is taken. - -=item B<-k>, B<--backwards>, B<--reverse-order> - -Process the list of files in reverse order, last file first. This prevents conflicts when renaming files to names which are currently taken but would be freed later during the process of renaming. - -=item B<-l>, B<--symlink> - -Create symlinks from the new names to the existing ones, instead of renaming the files. B.> - -=item B<-L>, B<--hardlink> - -Create hard links from the new names to the existing ones, instead of renaming the files. B.> - -=item B<-n>, B<--dry-run>, B<--just-print> - -Show how the files would be renamed, but don't actually do anything. - -=item B<-s>, B<--subst>, B<--simple> - -Perform a simple textual substitution of C to C. The C and C parameters must immediately follow the argument. - -Quoting issues aside, this is equivalent to supplying a C<-e 's/\Qfrom/to/'>. - -=item B<-v>, B<--verbose> - -Print additional information about the operations (not) executed. - -=item B<-z>, B<--sanitize> - -Replaces consecutive blanks, shell meta characters, and control characters in filenames with underscores. - -=back - -=head1 SEE ALSO - -mv(1), perl(1), find(1), grep(1), sort(1) - -=head1 BUGS - -None currently known. - -=head1 AUTHORS - -Aristotle Pagaltzis - -Idea, inspiration and original code from Larry Wall and Robin Barker. - -=head1 COPYRIGHT - -This script is free software; you can redistribute it and/or modify it under the same terms as Perl itself. - -=cut - -use Pod::Usage; -use Getopt::Long 2.24, qw(:config bundling no_ignore_case no_auto_abbrev); - -use constant ERROR => do { bless \(my $l = 0), 'LOGLEVEL' }; -use constant INFO => do { bless \(my $l = 1), 'LOGLEVEL' }; -use constant DEBUG => do { bless \(my $l = 2), 'LOGLEVEL' }; -use constant VERB_FOR => { - link => { - inf => 'link', - pastp => 'linked', - exec => sub { link shift, shift or die }, - }, - symlink => { - inf => 'symlink', - pastp => 'symlinked', - exec => sub { symlink shift, shift or die }, - }, - rename => { - inf => 'rename', - pastp => 'renamed', - exec => sub { rename shift, shift or die }, - }, -}; - -sub argv_to_subst_expr { - my $modifier = shift || ''; - pod2usage( -verbose => 1 ) if @ARGV < 2; - my ($from, $to) = map quotemeta, splice @ARGV, 0, 2; - # the ugly \${\""} construct is necessary because unknown backslash escapes are - # not treated the same in pattern- vs doublequote-quoting context; only the - # latter lets us do the right thing with problematic input like - # ']{ool(haracter$' or maybe '>>' - sprintf 's/\Q${\"%s"}/%s/%s', $from, $to, $modifier; -} - -my @EXPR; - -GetOptions( - 'h|help' => sub { pod2usage( -verbose => 1 ) }, - 'man' => sub { pod2usage( -verbose => 2 ) }, - '0|null' => \my $opt_null, - 'c|lower-case' => sub { push @EXPR, 's/([[:upper:]]+)/\L$1/g' }, - 'C|upper-case' => sub { push @EXPR, 's/([[:lower:]]+)/\U$1/g' }, - 'e|expr=s' => \@EXPR, - 'f|force' => \my $opt_force, - 'g|glob' => \my $opt_glob, - 'i|interactive' => \my $opt_interactive, - 'k|backwards|reverse-order' => \my $opt_backwards, - 'l|symlink' => \my $opt_symlink, - 'L|hardlink' => \my $opt_hardlink, - 'n|just-print|dry-run' => \my $opt_dryrun, - 'p|mkpath|make-dirs' => \my $opt_mkpath, - 'v|verbose+' => \(my $opt_verbose = 0), - 'z|sanitize' => sub { push @EXPR, 's/[!"\$&()=?`*\';<>|_[:cntrl:][:blank:]]+/_/g' }, - 's|subst|simple' => sub { push @EXPR, argv_to_subst_expr }, - 'S|subst-global' => sub { push @EXPR, argv_to_subst_expr('g') }, -) or pod2usage( -verbose => 1 ); - -die "TODO" if $opt_mkpath; - -if(not @EXPR) { - pod2usage( -verbose => 1 ) if not @ARGV or -e $ARGV[0]; - push @EXPR, shift; -} - -pod2usage( -verbose => 1 ) - if ($opt_hardlink and $opt_symlink) - or ($opt_null and @ARGV); - -++$opt_verbose if $opt_dryrun; - -BEGIN { - *CORE::GLOBAL::warn = sub { - if(ref $_[0] eq 'LOGLEVEL') { - my $msglevel = ${(shift)}; - print "@_\n" if $opt_verbose >= $msglevel; - return; - } - warn @_; - }; -} - -my $code = do { - my $cat = "sub { ".join('; ', @EXPR)." }"; - warn DEBUG, "Using expression: $cat"; - - my $evaled = eval $cat; - die $@ if $@; - die "Evaluation to subref failed. Check expression using -vn\n" - unless 'CODE' eq ref $evaled; - - $evaled; -}; - -my $verb = VERB_FOR->{ - $opt_hardlink ? 'link' : - $opt_symlink ? 'symlink' : - do { 'rename' } -}; - -if (!@ARGV) { - warn INFO, "Reading filenames from STDIN"; - @ARGV = do { - if($opt_null) { - warn INFO, "Splitting on NUL bytes"; - local $/ = "\0"; - } - ; - }; - chomp @ARGV; -} - -@ARGV = map glob, @ARGV if $opt_glob; - -@ARGV = reverse @ARGV if $opt_backwards; - -for (@ARGV) { - my $old = $_; - - $code->(); - - if($old eq $_) { - warn DEBUG, "'$old' unchanged"; - next; - } - - if(!$opt_force and -e) { - warn ERROR, "'$old' not $verb->{pastp}: '$_' already exists"; - next; - } - - if($opt_dryrun) { - warn INFO, "'$old' would be $verb->{pastp} to '$_'"; - next; - } - - if($opt_interactive) { - print "\u$verb->{inf} '$old' to '$_'? [n] "; - if( !~ /^y(?:es)?$/i) { - warn DEBUG, "Skipping '$old'."; - next; - } - } - - eval { $verb->{exec}($old, $_) }; - - if($@) { - warn ERROR, "Can't $verb->{inf} '$old' to '$_': $!"; - next; - } - - warn INFO, "'$old' $verb->{pastp} to '$_'"; -} diff --git a/bin/resample-dpi b/bin/resample-dpi deleted file mode 100755 index e7736a5..0000000 --- a/bin/resample-dpi +++ /dev/null @@ -1,38 +0,0 @@ -#!/usr/bin/env bash - -if [[ ! "$1" || "$1" == "-h" || "$1" == "--help" ]]; then cat </dev/null 2>&1 -done diff --git a/bin/shuffle-all b/bin/shuffle-all deleted file mode 100755 index 451a632..0000000 --- a/bin/shuffle-all +++ /dev/null @@ -1,5 +0,0 @@ -#!/bin/bash -mpc clear -mpc ls | mpc add -mpc play - diff --git a/bin/ssid b/bin/ssid deleted file mode 100755 index 776d70b..0000000 --- a/bin/ssid +++ /dev/null @@ -1,26 +0,0 @@ -#!/usr/bin/env bash - -if [[ "$1" == "-h" || "$1" == "--help" ]]; then cat < hr, -body > address { - display: none; -} diff --git a/copy/.gitconfig b/copy/.gitconfig index 4b08baa..3e2546d 100644 --- a/copy/.gitconfig +++ b/copy/.gitconfig @@ -1,6 +1,3 @@ -[user] - name = David Trudgian - email = EMAIL [core] excludesfile = ~/.gitignore_global [color] diff --git a/init/20_osx_homebrew.sh b/init/20_osx_homebrew.sh index a65657a..83ab0be 100644 --- a/init/20_osx_homebrew.sh +++ b/init/20_osx_homebrew.sh @@ -4,7 +4,7 @@ is_osx || return 1 # Install Homebrew. if [[ ! "$(type -P brew)" ]]; then e_header "Installing Homebrew" - true | ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" + true | /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" fi # Exit if, for some reason, Homebrew is not installed. diff --git a/init/30_osx_homebrew_casks.sh b/init/30_osx_homebrew_casks.sh index 1c605b3..3ee444e 100644 --- a/init/30_osx_homebrew_casks.sh +++ b/init/30_osx_homebrew_casks.sh @@ -12,10 +12,8 @@ casks=( caffeine emacs firefox - iterm2 sublime-merge sublime-text - tigervnc-viewer xquartz ) diff --git a/init/30_osx_homebrew_recipes.sh b/init/30_osx_homebrew_recipes.sh index e71ae8d..74df24d 100644 --- a/init/30_osx_homebrew_recipes.sh +++ b/init/30_osx_homebrew_recipes.sh @@ -11,7 +11,6 @@ recipes=( borgbackup coreutils ffmpeg - fish fzf gcc git diff --git a/link/.vim/autoload/plug.vim b/link/.vim/autoload/plug.vim index ad95041..652caa8 100644 --- a/link/.vim/autoload/plug.vim +++ b/link/.vim/autoload/plug.vim @@ -242,6 +242,8 @@ function! plug#begin(...) let home = s:path(s:plug_fnamemodify(s:plug_expand(a:1), ':p')) elseif exists('g:plug_home') let home = s:path(g:plug_home) + elseif has('nvim') + let home = stdpath('data') . '/plugged' elseif !empty(&rtp) let home = s:path(split(&rtp, ',')[0]) . '/plugged' else @@ -350,7 +352,7 @@ function! plug#end() endif let lod = { 'ft': {}, 'map': {}, 'cmd': {} } - if exists('g:did_load_filetypes') + if get(g:, 'did_load_filetypes', 0) filetype off endif for name in g:plugs_order @@ -2619,26 +2621,34 @@ function! s:preview_commit() let sha = matchstr(getline('.'), '^ \X*\zs[0-9a-f]\{7,9}') if empty(sha) - return + let name = matchstr(getline('.'), '^- \zs[^:]*\ze:$') + if empty(name) + return + endif + let title = 'HEAD@{1}..' + let command = 'git diff --no-color HEAD@{1}' + else + let title = sha + let command = 'git show --no-color --pretty=medium '.sha + let name = s:find_name(line('.')) endif - let name = s:find_name(line('.')) if empty(name) || !has_key(g:plugs, name) || !isdirectory(g:plugs[name].dir) return endif if exists('g:plug_pwindow') && !s:is_preview_window_open() execute g:plug_pwindow - execute 'e' sha + execute 'e' title else - execute 'pedit' sha + execute 'pedit' title wincmd P endif - setlocal previewwindow filetype=git buftype=nofile nobuflisted modifiable + setlocal previewwindow filetype=git buftype=nofile bufhidden=wipe nobuflisted modifiable let batchfile = '' try let [sh, shellcmdflag, shrd] = s:chsh(1) - let cmd = 'cd '.plug#shellescape(g:plugs[name].dir).' && git show --no-color --pretty=medium '.sha + let cmd = 'cd '.plug#shellescape(g:plugs[name].dir).' && '.command if s:is_win let [batchfile, cmd] = s:batchfile(cmd) endif @@ -2764,9 +2774,9 @@ function! s:snapshot(force, ...) abort 1 let anchor = line('$') - 3 let names = sort(keys(filter(copy(g:plugs), - \'has_key(v:val, "uri") && !has_key(v:val, "commit") && isdirectory(v:val.dir)'))) + \'has_key(v:val, "uri") && isdirectory(v:val.dir)'))) for name in reverse(names) - let sha = s:git_revision(g:plugs[name].dir) + let sha = has_key(g:plugs[name], 'commit') ? g:plugs[name].commit : s:git_revision(g:plugs[name].dir) if !empty(sha) call append(anchor, printf("silent! let g:plugs['%s'].commit = '%s'", name, sha)) redraw diff --git a/link/.vim/autoload/plug.vim.old b/link/.vim/autoload/plug.vim.old index b6e4cbf..ad95041 100644 --- a/link/.vim/autoload/plug.vim.old +++ b/link/.vim/autoload/plug.vim.old @@ -405,7 +405,7 @@ function! plug#end() for [map, names] in items(lod.map) for [mode, map_prefix, key_prefix] in - \ [['i', '', ''], ['n', '', ''], ['v', '', 'gv'], ['o', '', '']] + \ [['i', '', ''], ['n', '', ''], ['v', '', 'gv'], ['o', '', '']] execute printf( \ '%snoremap %s %s:call lod_map(%s, %s, %s, "%s")', \ mode, map, map_prefix, string(map), string(names), mode != 'i', key_prefix) diff --git a/link/.vimrc b/link/.vimrc index 8c5ff1d..22e980e 100644 --- a/link/.vimrc +++ b/link/.vimrc @@ -193,7 +193,6 @@ let g:airline#extensions#tabline#buffer_nr_show = 1 let g:plug_threads = 1 call plug#begin('~/.vim/plugged') Plug 'airblade/vim-gitgutter' -Plug 'dag/vim-fish' Plug 'fatih/vim-go' Plug 'kien/ctrlp.vim' Plug 'tpope/vim-commentary' diff --git a/source/00_dotfiles.sh b/source/00_dotfiles.sh index aa92865..27e0b36 100644 --- a/source/00_dotfiles.sh +++ b/source/00_dotfiles.sh @@ -1,5 +1,7 @@ +#!/usr/bin/env bash + # Sane default PATH across Linux, BSD, MacOS #export PATH="/bin:/sbin:/usr/bin:/usr/sbin:/usr/X11R7/bin:/usr/pkg/bin:/usr/pkg/sbin:/usr/games:/usr/local/bin:/usr/local/sbin" # Passing the "source" arg tells it to only define functions, then quit. -source $DOTFILES/bin/dotfiles "source" +source "$DOTFILES/bin/dotfiles" "source" diff --git a/source/10_user_bin.sh b/source/10_user_bin.sh index e1f778d..27e7460 100644 --- a/source/10_user_bin.sh +++ b/source/10_user_bin.sh @@ -1,3 +1,5 @@ +#!/usr/bin/env bash + export PATH="$HOME/bin:$HOME/.local/bin:$PATH" diff --git a/source/50_anaconda.sh b/source/50_anaconda.sh index fc14696..936e92f 100644 --- a/source/50_anaconda.sh +++ b/source/50_anaconda.sh @@ -1,12 +1,14 @@ +#!/usr/bin/env bash # anaconda if [ -d "$HOME/anaconda3/bin" ]; then - green='\033[0;32m' - NC='\033[0m' # No Color -# echo -e "${green}[dotfiles] anaconda available to activate - aconda${NC}" - + if [[ -n "$PS1" ]]; then + green='\033[0;32m' + NC='\033[0m' # No Color + echo -e "${green}[dotfiles] anaconda available to activate - aconda${NC}" + fi aconda() { export PATH="$HOME/anaconda3/bin:$PATH" diff --git a/source/50_editor.sh b/source/50_editor.sh index 22cfec0..929edf2 100644 --- a/source/50_editor.sh +++ b/source/50_editor.sh @@ -1,5 +1,5 @@ -# Editing +#!/usr/bin/env bash export EDITOR='emacsclient -c --alternate-editor=vim' export VISUAL="$EDITOR" -alias e="$EDITOR" +alias e="\$EDITOR" diff --git a/source/50_file.sh b/source/50_file.sh index 25d3a26..38ce874 100644 --- a/source/50_file.sh +++ b/source/50_file.sh @@ -1,3 +1,5 @@ +#!/usr/bin/env bash + # Files will be created with these permissions: # files 644 -rw-r--r-- (666 minus 022) # dirs 755 drwxr-xr-x (777 minus 022) @@ -21,12 +23,3 @@ alias df="df -h" # Recursively delete `.DS_Store` files alias dsstore="find . -name '*.DS_Store' -type f -ls -delete" - -# Aliasing eachdir like this allows you to use aliases/functions as commands. -alias eachdir=". eachdir" - -# Create a new directory and enter it -function md() { - mkdir -p "$@" && cd "$@" -} - diff --git a/source/50_go.sh b/source/50_go.sh index a18378a..6e47041 100644 --- a/source/50_go.sh +++ b/source/50_go.sh @@ -1,3 +1,5 @@ +#!/usr/bin/env bash + if [ -d "/opt/go" ]; then export PATH="/opt/go/bin:$PATH" fi diff --git a/source/50_gpg.sh b/source/50_gpg.sh index 2f9c6d9..3df5e3c 100644 --- a/source/50_gpg.sh +++ b/source/50_gpg.sh @@ -1,2 +1,5 @@ -export GPG_TTY=$(tty) +#!/usr/bin/env bash + +GPG_TTY=$(tty) +export GPG_TTY diff --git a/source/50_keychain.sh b/source/50_keychain.sh index 59d46cf..e2b0f56 100644 --- a/source/50_keychain.sh +++ b/source/50_keychain.sh @@ -1,5 +1,7 @@ -if [[ ! -z "$PS1" ]]; then +#!/usr/bin/env bash + +if [[ -n "$PS1" ]]; then if command -v keychain &> /dev/null; then - eval $(keychain --eval --agents ssh id_rsa id_ed25519) + eval "$(keychain --eval --agents ssh id_rsa id_ed25519)" fi fi diff --git a/source/50_misc.sh b/source/50_misc.sh index f4c78c0..1805fb9 100644 --- a/source/50_misc.sh +++ b/source/50_misc.sh @@ -1,3 +1,5 @@ +#!/usr/bin/env bash + # Prevent less from clearing the screen while still showing colors. export LESS=-XR @@ -7,9 +9,9 @@ function titlebar() { } # SSH auto-completion based on entries in known_hosts. -if [ ! -n "$ZSH" ]; then +if [ -z "$ZSH" ]; then if [[ -e ~/.ssh/known_hosts ]]; then - complete -o default -W "$(cat ~/.ssh/known_hosts | sed 's/[, ].*//' | sort | uniq | grep -v '[0-9]')" ssh scp sftp + complete -o default -W "$(sed 's/[, ].*//' ~/.ssh/known_hosts | sort | uniq | grep -v '[0-9]')" ssh scp sftp fi fi diff --git a/source/50_npm.sh b/source/50_npm.sh index b4923c3..6d178a3 100644 --- a/source/50_npm.sh +++ b/source/50_npm.sh @@ -1,3 +1,5 @@ +#!/usr/bin/env bash + export NPM_PACKAGES="$HOME/.npm-packages" export PATH="$PATH:$HOME/.npm-packages/bin" diff --git a/source/50_perl5.sh b/source/50_perl5.sh index 38f20bd..fba1b5f 100644 --- a/source/50_perl5.sh +++ b/source/50_perl5.sh @@ -1,3 +1,5 @@ +#!/usr/bin/env bash + if [ -d "${HOME}/perl5" ]; then export PERL5LIB="$HOME/perl5/lib/perl5" export PATH="$HOME/perl5/bin:$PATH" diff --git a/source/50_prompt.sh b/source/50_prompt.sh index 2debe6b..c851ded 100644 --- a/source/50_prompt.sh +++ b/source/50_prompt.sh @@ -1,4 +1,6 @@ -if [ ! -n "$ZSH" ]; then +#!/usr/bin/env bash + +if [ -z "$ZSH" ]; then export PS1="\[\e[31m\]\u\[\e[33m\]@\[\e[34m\]\h\[\e[m\]:\[\e[35m\]\w\[\e[m\]\n\[\e[36m\]\@\[\e[m\] $ " fi diff --git a/source/50_pyenv.sh b/source/50_pyenv.sh index 12ea6dc..a49d60b 100644 --- a/source/50_pyenv.sh +++ b/source/50_pyenv.sh @@ -1,4 +1,4 @@ -#pyenv +#!/usr/bin/env bash if [ -d "$HOME/.pyenv" ]; then diff --git a/source/50_rbenv.sh b/source/50_rbenv.sh index 23161c5..4fcf607 100644 --- a/source/50_rbenv.sh +++ b/source/50_rbenv.sh @@ -1,4 +1,4 @@ -# rbenv +#!/usr/bin/env bash if [ -d "$HOME/.rbenv" ]; then diff --git a/source/50_remote.sh b/source/50_remote.sh index 6c002c9..121cab5 100644 --- a/source/50_remote.sh +++ b/source/50_remote.sh @@ -1,8 +1,7 @@ +#!/usr/bin/env bash + alias sdf="mosh dctrud@iceland.sdf.org -- tmux a" alias sdfnew="mosh dctrud@iceland.sdf.org -- tmux" alias club="mosh dctrud@tilde.club -- tmux a" alias clubnew="mosh dctrud@tilde.club -- tmux" - -alias rr="mosh ubuntu@randomroad.net -- tmux a" -alias rrnew="mosh ubuntu@petroc.randomroad.net -- tmux" diff --git a/source/50_singularity.sh b/source/50_singularity.sh index ce44be2..6e918cc 100644 --- a/source/50_singularity.sh +++ b/source/50_singularity.sh @@ -1,3 +1,5 @@ +#!/usr/bin/env bash + alias sbuild="rm -rf builddir && ./mconfig -v && make -C builddir && sudo make -C builddir install" alias k="minikube kubectl -- " diff --git a/vendor/rename/README.txt b/vendor/rename/README.txt deleted file mode 100644 index 1eb3fc5..0000000 --- a/vendor/rename/README.txt +++ /dev/null @@ -1,6 +0,0 @@ -rename 0.1.3 -Wednesday, Nov 4, 2009, 00:35 -Aristotle Pagaltzis -http://plasmasturm.org/code/rename/ - -Note: downloaded directly because there's no repo to include. diff --git a/vendor/rename/rename b/vendor/rename/rename deleted file mode 100644 index eb115b6..0000000 --- a/vendor/rename/rename +++ /dev/null @@ -1,310 +0,0 @@ -#!/usr/bin/perl -use strict; -use warnings; - -=head1 NAME - -rename - renames multiple files - -=head1 SYNOPSIS - -F -S> - -F -S> - -F -S> -S> -S> -S> -S> -S> -S> -S> -S> -S> -S> - -=head1 DESCRIPTION - -C renames the filenames supplied according to the rules specified. If a given filename is not modified, it will not be renamed. If no filenames are given on the command line, filenames will be read via standard input. - -For example, to rename all files matching C<*.bak> to strip the extension, you might say - - rename 's/\.bak$//' *.bak - -If are confident that none of the filenames has C<.bak> anywhere else than at the end, you can also use the much easier typed - - rename -s .bak '' *.bak - -You can always do multiple changes in one ago: - - rename -s .tgz .tar.gz -s .tbz2 .tar.bz2 *.tar.* - -Note however that expressive options are order sensitive. The following would probably surprise you: - - rename -s foo bar -s bar baz * - -Since operations are cumulative, this would end up substituting (some of) the F matches in filenames with F! So pay attention to order. You may want to request a verbose dry run with C<-nv> for the first stab at a complex rename operation. - - rename -nv -s bar baz -s foo bar * - -You can combine the various expressive options to suit your needs. F.ex files from Microsoft(tm) Windows systems often have blanks and (sometimes nothing but) capital letters in their names. Let's say you have a bunch of such files to clean up, and you also want to move them to subdirectories based on extension. The following command should help, provided all directories already exist: - - rename -cz -e '$_ = "$1/$_" if /(\..*)\z/' * - -Again you need to pay attention to order sensitivity for expressive options. If you placed the C<-c> after the C<-e> in the above example, files with F<.zip> and F<.ZIP> extensions would be (attempted to be) moved to different directories because the directory name prefix would be added before the filenames were normalized. Once again, use verbose dry run requested using C<-nv> to get an idea of what exactly a complex rename operation is going to do. - -=head1 ARGUMENTS - -=over 4 - -=item B<-h>, B<--help> - -See a synopsis. - -=item B<--man> - -Browse the manpage. - -=back - -=head1 OPTIONS - -=over 4 - -=item B<-0>, B<--null> - -When reading file names from C, split on NUL bytes instead of newlines. This is useful in combination with GNU find's C<-print0> option, GNU grep's C<-Z> option, and GNU sort's C<-z> option, to name just a few. B - -=item B<-c>, B<--lower-case> - -Converts file names to all lower case. - -=item B<-C>, B<--upper-case> - -Converts file names to all upper case. - -=item B<-e>, B<--expr> - -The C argument to this option should be a Perl expression that assumes the filename in the C<$_> variable and modifies it for the filenames to be renamed. When no other C<-c>, C<-C>, C<-e>, C<-s>, or C<-z> options are given, you can omit the C<-e> from infront of the code. - -=item B<-g>, B<--glob> - -Glob filename arguments. This is useful if you're using a braindead shell such as F which won't expand wildcards on behalf of the user. - -=item B<-f>, B<--force> - -Rename even when a file with the destination name already exists. - -=item B<-i>, B<--interactive> - -Ask the user to confirm every action before it is taken. - -=item B<-k>, B<--backwards>, B<--reverse-order> - -Process the list of files in reverse order, last file first. This prevents conflicts when renaming files to names which are currently taken but would be freed later during the process of renaming. - -=item B<-l>, B<--symlink> - -Create symlinks from the new names to the existing ones, instead of renaming the files. B.> - -=item B<-L>, B<--hardlink> - -Create hard links from the new names to the existing ones, instead of renaming the files. B.> - -=item B<-n>, B<--dry-run>, B<--just-print> - -Show how the files would be renamed, but don't actually do anything. - -=item B<-s>, B<--subst>, B<--simple> - -Perform a simple textual substitution of C to C. The C and C parameters must immediately follow the argument. - -Quoting issues aside, this is equivalent to supplying a C<-e 's/\Qfrom/to/'>. - -=item B<-v>, B<--verbose> - -Print additional information about the operations (not) executed. - -=item B<-z>, B<--sanitize> - -Replaces consecutive blanks, shell meta characters, and control characters in filenames with underscores. - -=back - -=head1 SEE ALSO - -mv(1), perl(1), find(1), grep(1), sort(1) - -=head1 BUGS - -None currently known. - -=head1 AUTHORS - -Aristotle Pagaltzis - -Idea, inspiration and original code from Larry Wall and Robin Barker. - -=head1 COPYRIGHT - -This script is free software; you can redistribute it and/or modify it under the same terms as Perl itself. - -=cut - -use Pod::Usage; -use Getopt::Long 2.24, qw(:config bundling no_ignore_case no_auto_abbrev); - -use constant ERROR => do { bless \(my $l = 0), 'LOGLEVEL' }; -use constant INFO => do { bless \(my $l = 1), 'LOGLEVEL' }; -use constant DEBUG => do { bless \(my $l = 2), 'LOGLEVEL' }; -use constant VERB_FOR => { - link => { - inf => 'link', - pastp => 'linked', - exec => sub { link shift, shift or die }, - }, - symlink => { - inf => 'symlink', - pastp => 'symlinked', - exec => sub { symlink shift, shift or die }, - }, - rename => { - inf => 'rename', - pastp => 'renamed', - exec => sub { rename shift, shift or die }, - }, -}; - -sub argv_to_subst_expr { - my $modifier = shift || ''; - pod2usage( -verbose => 1 ) if @ARGV < 2; - my ($from, $to) = map quotemeta, splice @ARGV, 0, 2; - # the ugly \${\""} construct is necessary because unknown backslash escapes are - # not treated the same in pattern- vs doublequote-quoting context; only the - # latter lets us do the right thing with problematic input like - # ']{ool(haracter$' or maybe '>>' - sprintf 's/\Q${\"%s"}/%s/%s', $from, $to, $modifier; -} - -my @EXPR; - -GetOptions( - 'h|help' => sub { pod2usage( -verbose => 1 ) }, - 'man' => sub { pod2usage( -verbose => 2 ) }, - '0|null' => \my $opt_null, - 'c|lower-case' => sub { push @EXPR, 's/([[:upper:]]+)/\L$1/g' }, - 'C|upper-case' => sub { push @EXPR, 's/([[:lower:]]+)/\U$1/g' }, - 'e|expr=s' => \@EXPR, - 'f|force' => \my $opt_force, - 'g|glob' => \my $opt_glob, - 'i|interactive' => \my $opt_interactive, - 'k|backwards|reverse-order' => \my $opt_backwards, - 'l|symlink' => \my $opt_symlink, - 'L|hardlink' => \my $opt_hardlink, - 'n|just-print|dry-run' => \my $opt_dryrun, - 'p|mkpath|make-dirs' => \my $opt_mkpath, - 'v|verbose+' => \(my $opt_verbose = 0), - 'z|sanitize' => sub { push @EXPR, 's/[!"\$&()=?`*\';<>|_[:cntrl:][:blank:]]+/_/g' }, - 's|subst|simple' => sub { push @EXPR, argv_to_subst_expr }, - 'S|subst-global' => sub { push @EXPR, argv_to_subst_expr('g') }, -) or pod2usage( -verbose => 1 ); - -die "TODO" if $opt_mkpath; - -if(not @EXPR) { - pod2usage( -verbose => 1 ) if not @ARGV or -e $ARGV[0]; - push @EXPR, shift; -} - -pod2usage( -verbose => 1 ) - if ($opt_hardlink and $opt_symlink) - or ($opt_null and @ARGV); - -++$opt_verbose if $opt_dryrun; - -BEGIN { - *CORE::GLOBAL::warn = sub { - if(ref $_[0] eq 'LOGLEVEL') { - my $msglevel = ${(shift)}; - print "@_\n" if $opt_verbose >= $msglevel; - return; - } - warn @_; - }; -} - -my $code = do { - my $cat = "sub { ".join('; ', @EXPR)." }"; - warn DEBUG, "Using expression: $cat"; - - my $evaled = eval $cat; - die $@ if $@; - die "Evaluation to subref failed. Check expression using -vn\n" - unless 'CODE' eq ref $evaled; - - $evaled; -}; - -my $verb = VERB_FOR->{ - $opt_hardlink ? 'link' : - $opt_symlink ? 'symlink' : - do { 'rename' } -}; - -if (!@ARGV) { - warn INFO, "Reading filenames from STDIN"; - @ARGV = do { - if($opt_null) { - warn INFO, "Splitting on NUL bytes"; - local $/ = "\0"; - } - ; - }; - chomp @ARGV; -} - -@ARGV = map glob, @ARGV if $opt_glob; - -@ARGV = reverse @ARGV if $opt_backwards; - -for (@ARGV) { - my $old = $_; - - $code->(); - - if($old eq $_) { - warn DEBUG, "'$old' unchanged"; - next; - } - - if(!$opt_force and -e) { - warn ERROR, "'$old' not $verb->{pastp}: '$_' already exists"; - next; - } - - if($opt_dryrun) { - warn INFO, "'$old' would be $verb->{pastp} to '$_'"; - next; - } - - if($opt_interactive) { - print "\u$verb->{inf} '$old' to '$_'? [n] "; - if( !~ /^y(?:es)?$/i) { - warn DEBUG, "Skipping '$old'."; - next; - } - } - - eval { $verb->{exec}($old, $_) }; - - if($@) { - warn ERROR, "Can't $verb->{inf} '$old' to '$_': $!"; - next; - } - - warn INFO, "'$old' $verb->{pastp} to '$_'"; -}