Make head commands BSD compatible
parent
9b4a049571
commit
f49b7bfced
|
|
@ -19,7 +19,7 @@ case $OSTYPE in
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
if [ ! -z "$(command ls "${BASH_IT}/enabled/"{[0-9][0-9][0-9]${BASH_IT_LOAD_PRIORITY_SEPARATOR}docker,docker}.plugin.bash 2>/dev/null | head -1)" ]; then
|
if [ ! -z "$(command ls "${BASH_IT}/enabled/"{[0-9][0-9][0-9]${BASH_IT_LOAD_PRIORITY_SEPARATOR}docker,docker}.plugin.bash 2>/dev/null | head -n 1)" ]; then
|
||||||
# Function aliases from docker plugin:
|
# Function aliases from docker plugin:
|
||||||
alias dkrmlc='docker-remove-most-recent-container' # Delete most recent (i.e., last) Docker container
|
alias dkrmlc='docker-remove-most-recent-container' # Delete most recent (i.e., last) Docker container
|
||||||
alias dkrmall='docker-remove-stale-assets' # Delete all untagged images and exited containers
|
alias dkrmall='docker-remove-stale-assets' # Delete all untagged images and exited containers
|
||||||
|
|
|
||||||
|
|
@ -16,8 +16,8 @@ _bash-it-comp-list-available-not-enabled()
|
||||||
do
|
do
|
||||||
file_entity=$(basename $f)
|
file_entity=$(basename $f)
|
||||||
|
|
||||||
typeset enabled_component=$(command ls "${BASH_IT}/$subdirectory/enabled/"{[0-9]*$BASH_IT_LOAD_PRIORITY_SEPARATOR$file_entity,$file_entity} 2>/dev/null | head -1)
|
typeset enabled_component=$(command ls "${BASH_IT}/$subdirectory/enabled/"{[0-9]*$BASH_IT_LOAD_PRIORITY_SEPARATOR$file_entity,$file_entity} 2>/dev/null | head -n 1)
|
||||||
typeset enabled_component_global=$(command ls "${BASH_IT}/enabled/"[0-9]*$BASH_IT_LOAD_PRIORITY_SEPARATOR$file_entity 2>/dev/null | head -1)
|
typeset enabled_component_global=$(command ls "${BASH_IT}/enabled/"[0-9]*$BASH_IT_LOAD_PRIORITY_SEPARATOR$file_entity 2>/dev/null | head -n 1)
|
||||||
|
|
||||||
if [ -z "$enabled_component" ] && [ -z "$enabled_component_global" ]
|
if [ -z "$enabled_component" ] && [ -z "$enabled_component_global" ]
|
||||||
then
|
then
|
||||||
|
|
|
||||||
|
|
@ -70,7 +70,7 @@ function __fab_fabfile_mtime() {
|
||||||
else
|
else
|
||||||
# Suppose that it's a fabfile dir
|
# Suppose that it's a fabfile dir
|
||||||
find $f/*.py -exec ${__FAB_COMPLETION_MTIME_COMMAND} {} + \
|
find $f/*.py -exec ${__FAB_COMPLETION_MTIME_COMMAND} {} + \
|
||||||
| xargs -n 1 expr | sort -n -r | head -1
|
| xargs -n 1 expr | sort -n -r | head -n 1
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -190,10 +190,10 @@ draft ()
|
||||||
if [ -n "$myopic" ]; then
|
if [ -n "$myopic" ]; then
|
||||||
lines=2
|
lines=2
|
||||||
fi
|
fi
|
||||||
cmd=$(fc -ln -$lines | head -1 | sed 's/^[[:blank:]]*//')
|
cmd=$(fc -ln -$lines | head -n 1 | sed 's/^[[:blank:]]*//')
|
||||||
else
|
else
|
||||||
# parse command from history line number
|
# parse command from history line number
|
||||||
cmd=$(eval "history | grep '^[[:blank:]]*$num' | head -1" | sed 's/^[[:blank:][:digit:]]*//')
|
cmd=$(eval "history | grep '^[[:blank:]]*$num' | head -n 1" | sed 's/^[[:blank:][:digit:]]*//')
|
||||||
fi
|
fi
|
||||||
eval "$func() { $cmd; }"
|
eval "$func() { $cmd; }"
|
||||||
typeset file=$(mktemp -t draft.XXXX)
|
typeset file=$(mktemp -t draft.XXXX)
|
||||||
|
|
|
||||||
|
|
@ -371,13 +371,13 @@ _disable-thing ()
|
||||||
rm "$f"
|
rm "$f"
|
||||||
done
|
done
|
||||||
else
|
else
|
||||||
typeset plugin_global=$(command ls $ "${BASH_IT}/enabled/"[0-9]*$BASH_IT_LOAD_PRIORITY_SEPARATOR$file_entity.$suffix.bash 2>/dev/null | head -1)
|
typeset plugin_global=$(command ls $ "${BASH_IT}/enabled/"[0-9]*$BASH_IT_LOAD_PRIORITY_SEPARATOR$file_entity.$suffix.bash 2>/dev/null | head -n 1)
|
||||||
if [ -z "$plugin_global" ]; then
|
if [ -z "$plugin_global" ]; then
|
||||||
# Use a glob to search for both possible patterns
|
# Use a glob to search for both possible patterns
|
||||||
# 250---node.plugin.bash
|
# 250---node.plugin.bash
|
||||||
# node.plugin.bash
|
# node.plugin.bash
|
||||||
# Either one will be matched by this glob
|
# Either one will be matched by this glob
|
||||||
typeset plugin=$(command ls $ "${BASH_IT}/$subdirectory/enabled/"{[0-9]*$BASH_IT_LOAD_PRIORITY_SEPARATOR$file_entity.$suffix.bash,$file_entity.$suffix.bash} 2>/dev/null | head -1)
|
typeset plugin=$(command ls $ "${BASH_IT}/$subdirectory/enabled/"{[0-9]*$BASH_IT_LOAD_PRIORITY_SEPARATOR$file_entity.$suffix.bash,$file_entity.$suffix.bash} 2>/dev/null | head -n 1)
|
||||||
if [ -z "$plugin" ]; then
|
if [ -z "$plugin" ]; then
|
||||||
printf '%s\n' "sorry, $file_entity does not appear to be an enabled $file_type."
|
printf '%s\n' "sorry, $file_entity does not appear to be an enabled $file_type."
|
||||||
return
|
return
|
||||||
|
|
@ -458,7 +458,7 @@ _enable-thing ()
|
||||||
_enable-thing $subdirectory $file_type $to_enable $load_priority
|
_enable-thing $subdirectory $file_type $to_enable $load_priority
|
||||||
done
|
done
|
||||||
else
|
else
|
||||||
typeset to_enable=$(command ls "${BASH_IT}/$subdirectory/available/"$file_entity.*bash 2>/dev/null | head -1)
|
typeset to_enable=$(command ls "${BASH_IT}/$subdirectory/available/"$file_entity.*bash 2>/dev/null | head -n 1)
|
||||||
if [ -z "$to_enable" ]; then
|
if [ -z "$to_enable" ]; then
|
||||||
printf '%s\n' "sorry, $file_entity does not appear to be an available $file_type."
|
printf '%s\n' "sorry, $file_entity does not appear to be an available $file_type."
|
||||||
return
|
return
|
||||||
|
|
@ -466,13 +466,13 @@ _enable-thing ()
|
||||||
|
|
||||||
to_enable=$(basename $to_enable)
|
to_enable=$(basename $to_enable)
|
||||||
# Check for existence of the file using a wildcard, since we don't know which priority might have been used when enabling it.
|
# Check for existence of the file using a wildcard, since we don't know which priority might have been used when enabling it.
|
||||||
typeset enabled_plugin=$(command ls "${BASH_IT}/$subdirectory/enabled/"{[0-9][0-9][0-9]$BASH_IT_LOAD_PRIORITY_SEPARATOR$to_enable,$to_enable} 2>/dev/null | head -1)
|
typeset enabled_plugin=$(command ls "${BASH_IT}/$subdirectory/enabled/"{[0-9][0-9][0-9]$BASH_IT_LOAD_PRIORITY_SEPARATOR$to_enable,$to_enable} 2>/dev/null | head -n 1)
|
||||||
if [ ! -z "$enabled_plugin" ] ; then
|
if [ ! -z "$enabled_plugin" ] ; then
|
||||||
printf '%s\n' "$file_entity is already enabled."
|
printf '%s\n' "$file_entity is already enabled."
|
||||||
return
|
return
|
||||||
fi
|
fi
|
||||||
|
|
||||||
typeset enabled_plugin_global=$(command compgen -G "${BASH_IT}/enabled/[0-9][0-9][0-9]$BASH_IT_LOAD_PRIORITY_SEPARATOR$to_enable" 2>/dev/null | head -1)
|
typeset enabled_plugin_global=$(command compgen -G "${BASH_IT}/enabled/[0-9][0-9][0-9]$BASH_IT_LOAD_PRIORITY_SEPARATOR$to_enable" 2>/dev/null | head -n 1)
|
||||||
if [ ! -z "$enabled_plugin_global" ] ; then
|
if [ ! -z "$enabled_plugin_global" ] ; then
|
||||||
printf '%s\n' "$file_entity is already enabled."
|
printf '%s\n' "$file_entity is already enabled."
|
||||||
return
|
return
|
||||||
|
|
|
||||||
|
|
@ -57,19 +57,19 @@ battery_percentage(){
|
||||||
|
|
||||||
if _command_exists upower;
|
if _command_exists upower;
|
||||||
then
|
then
|
||||||
COMMAND_OUTPUT=$(upower --show-info $(upower --enumerate | grep -i BAT) | grep percentage | grep -o "[0-9]\+" | head -1)
|
COMMAND_OUTPUT=$(upower --show-info $(upower --enumerate | grep -i BAT) | grep percentage | grep -o "[0-9]\+" | head -n 1)
|
||||||
elif _command_exists acpi;
|
elif _command_exists acpi;
|
||||||
then
|
then
|
||||||
COMMAND_OUTPUT=$(acpi -b | awk -F, '/,/{gsub(/ /, "", $0); gsub(/%/,"", $0); print $2}' )
|
COMMAND_OUTPUT=$(acpi -b | awk -F, '/,/{gsub(/ /, "", $0); gsub(/%/,"", $0); print $2}' )
|
||||||
elif _command_exists pmset;
|
elif _command_exists pmset;
|
||||||
then
|
then
|
||||||
COMMAND_OUTPUT=$(pmset -g ps | sed -n 's/.*[[:blank:]]+*\(.*%\).*/\1/p' | grep -o "[0-9]\+" | head -1)
|
COMMAND_OUTPUT=$(pmset -g ps | sed -n 's/.*[[:blank:]]+*\(.*%\).*/\1/p' | grep -o "[0-9]\+" | head -n 1)
|
||||||
elif _command_exists ioreg;
|
elif _command_exists ioreg;
|
||||||
then
|
then
|
||||||
COMMAND_OUTPUT=$(ioreg -n AppleSmartBattery -r | awk '$1~/Capacity/{c[$1]=$3} END{OFMT="%05.2f"; max=c["\"MaxCapacity\""]; print (max>0? 100*c["\"CurrentCapacity\""]/max: "?")}' | grep -o "[0-9]\+" | head -1)
|
COMMAND_OUTPUT=$(ioreg -n AppleSmartBattery -r | awk '$1~/Capacity/{c[$1]=$3} END{OFMT="%05.2f"; max=c["\"MaxCapacity\""]; print (max>0? 100*c["\"CurrentCapacity\""]/max: "?")}' | grep -o "[0-9]\+" | head -n 1)
|
||||||
elif _command_exists WMIC;
|
elif _command_exists WMIC;
|
||||||
then
|
then
|
||||||
COMMAND_OUTPUT=$(WMIC PATH Win32_Battery Get EstimatedChargeRemaining /Format:List | grep -o '[0-9]\+' | head -1)
|
COMMAND_OUTPUT=$(WMIC PATH Win32_Battery Get EstimatedChargeRemaining /Format:List | grep -o '[0-9]\+' | head -n 1)
|
||||||
else
|
else
|
||||||
COMMAND_OUTPUT="no"
|
COMMAND_OUTPUT="no"
|
||||||
fi
|
fi
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,7 @@ function docker-remove-most-recent-container() {
|
||||||
function docker-remove-most-recent-image() {
|
function docker-remove-most-recent-image() {
|
||||||
about 'attempt to remove the most recent image from docker images'
|
about 'attempt to remove the most recent image from docker images'
|
||||||
group 'docker'
|
group 'docker'
|
||||||
docker images -q | head -1 | xargs docker rmi
|
docker images -q | head -n 1 | xargs docker rmi
|
||||||
}
|
}
|
||||||
|
|
||||||
function docker-remove-stale-assets() {
|
function docker-remove-stale-assets() {
|
||||||
|
|
|
||||||
|
|
@ -152,8 +152,8 @@ function v2gif {
|
||||||
else
|
else
|
||||||
fps=$defaultfps
|
fps=$defaultfps
|
||||||
if [[ -x $mediainfo ]] ; then
|
if [[ -x $mediainfo ]] ; then
|
||||||
fps=$($mediainfo "$file" | grep "Frame rate " |sed 's/.*: \([0-9.]\+\) .*/\1/' | head -1)
|
fps=$($mediainfo "$file" | grep "Frame rate " |sed 's/.*: \([0-9.]\+\) .*/\1/' | head -n 1)
|
||||||
[[ -z "$fps" ]] && fps=$($mediainfo "$file" | grep "Minimum frame rate" |sed 's/.*: \([0-9.]\+\) .*/\1/' | head -1)
|
[[ -z "$fps" ]] && fps=$($mediainfo "$file" | grep "Minimum frame rate" |sed 's/.*: \([0-9.]\+\) .*/\1/' | head -n 1)
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue