4 ms·
Here's a handy delta trick for you, to turn the side-by-side feature on and off based on window size. bash here, other shells left as an exercise: function d
by wlonkly 2y ago
Here's a handy delta trick for you, to turn the side-by-side feature on and off based on window size. bash here, other shells left as an exercise:
function delta_sidebyside {
if [[ COLUMNS -ge 120 ]]; then
DELTA_FEATURES='side-by-side'
else
DELTA_FEATURES=''
fi
}
trap delta_sidebyside WINCH
- dbtablesorrows 2y agoYou are probably missing a $ before COLUMNS and export before setting DELTA_FEATURES
- wlonkly 2y agoBash is funny with the -gt, -lt etc. operators and the [[ ]] builtin -- bash treats them as arithmetic operators like it does with math in $(( )), and so you provide them the variable name, not the value. $ TEST=3 $ if [[ TEST -gt 2 ]]; then echo "honk"; fi honk $ TEST=1 $ if [[ TEST -gt 2 ]]; then echo "honk"; fi $ That lets you do things like $ if [[ TEST*3 -gt 6 ]]; ... without having to nest even more double parentheses. You're correct about having to export DELTA_FEATURES at least once. (I export it outside of the function, but no harm in doing so whenever it's set -- but it's not required to re-export it when you change the value.) Thanks for catching that!