Skip to content
This repository has been archived by the owner on Nov 11, 2018. It is now read-only.

bash script improvements #357

Merged
merged 1 commit into from
Sep 23, 2014
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 9 additions & 13 deletions data/Startup/bash_startup.in
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,10 @@ PS1=$PS1$(final_term_control_sequence 'B')
# Logic for terminal commands

function trim() {
echo "$1" | sed -e 's/^ *//g' -e 's/ *$//g'
local text=$1
text="${text#"${text%%[![:space:]]*}"}" # remove leading whitespace characters
text="${text%"${text##*[![:space:]]}"}" # remove trailing whitespace characters
echo -n "$text"
}

function send_commands() {
Expand All @@ -73,18 +76,11 @@ while IFS= read -r line; do
# Non-empty line
if [ "${stripped_line:0:1}" != "#" ]; then
# Non-comment line
# Split on "=" character
old_IFS=$IFS
IFS='='
line_parts=($stripped_line)
IFS=$old_IFS

name=$(trim "${line_parts[0]}")
commands=$(trim "${line_parts[1]}")
# Escape double quotes used for command arguments
commands=$(echo "$commands" | sed 's/"/\\"/g')

alias ",$name"="send_commands \"$commands\""
# Split on "=" character and escape double quotes used for command arguments
name=$(trim "${stripped_line%%=*}")
cmds=$(trim "${stripped_line#*=}")
cmds=${cmds//\"/\\\"}
alias ",$name"="send_commands \"${cmds}\""
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is much cleaner than the previous solution; great stuff!

fi
fi
done <*.ftcommands
Expand Down