Add suppot for multiline snippets (#91)

Fix #88
This commit is contained in:
Denis Isidoro 2019-09-27 11:42:49 -03:00
parent 00a2d2b91e
commit b9084c0439
2 changed files with 32 additions and 3 deletions

View File

@ -1,10 +1,19 @@
% network
# Kill a process running on a given port
lsof -i :<port> | awk '{l=$2} END {print l}' | xargs kill
lsof -i :<port> \
| awk '{l=$2} END {print l}' \
| xargs kill
# List IP addresses connected on a given port
netstat -tn 2>/dev/null | grep :<port> | awk '{print $5}' | cut -d: -f1 | sort | uniq -c | sort -nr | head
netstat -tn 2>/dev/null \
| grep :<port> \
| awk '{print $5}' \
| cut -d: -f1 \
| sort \
| uniq -c \
| sort -nr \
| head
# Find external, public IP address
dig +short myip.opendns.com @resolver1.opendns.com

View File

@ -6,10 +6,25 @@ cheat::find() {
done
}
cheat::_join_multiline_using_sed() {
tr '\n' '\f' \
| sed -E 's/\\\f *//g' \
| tr '\f' '\n'
}
cheat::_join_multiline() {
if ${NAVI_USE_PERL:-false}; then
perl -0pe 's/\\\n *//g' \
|| cheat::_join_multiline_using_sed
else
cheat::_join_multiline_using_sed
fi
}
cheat::read_all() {
for cheat in $(cheat::find); do
echo
cat "$cheat"
cat "$cheat" | cheat::_join_multiline
echo
done
}
@ -19,6 +34,11 @@ cheat::memoized_read_all() {
echo "$NAVI_CACHE"
return
fi
if command_exists perl; then
export NAVI_USE_PERL=true
else
export NAVI_USE_PERL=false
fi
local -r cheats="$(cheat::read_all)"
echo "$cheats"
}