Skip to content

Commit

Permalink
Follow up commit for issue #6
Browse files Browse the repository at this point in the history
-Replace ignoreboth with simpley ignoredups
  • Loading branch information
rcaloras committed Jun 21, 2015
1 parent 69a8ac0 commit 7e55ac1
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 7 deletions.
20 changes: 15 additions & 5 deletions bash-preexec.sh
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,18 @@ fi
__bp_imported="defined"


# Remove ignorespace from HISTCONTROL so we can accurately
# invoke preexec with a command from our history even if it
# starts with a space.
export HISTCONTROL="${HISTCONTROL//ignorespace}"

# Remove ignorespace and or replace ignoreboth from HISTCONTROL
# so we can accurately invoke preexec with a command from our
# history even if it starts with a space.
__bp_adjust_histcontrol() {
local histcontrol
histcontrol="${HISTCONTROL//ignorespace}"
# Replace ignoreboth with ignoredups
if [[ "$histcontrol" == *"ignoreboth"* ]]; then
histcontrol="ignoredups:${histcontrol//ignoreboth}"
fi;
export HISTCONTROL="$histcontrol"
}

# This variable describes whether we are currently in "interactive mode";
# i.e. whether this shell has just executed a prompt and is waiting for user
Expand Down Expand Up @@ -188,6 +195,9 @@ __bp_preexec_and_precmd_install() {
return 1;
fi

# Adjust our HISTCONTROL Variable if needed.
__bp_adjust_histcontrol

# Take our existing prompt command and append a semicolon to it
# if it doesn't already have one.
local existing_prompt_command
Expand Down
17 changes: 15 additions & 2 deletions test/bash-preexec.bats
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,22 @@ test_preexec_echo() {

}

@test "HISTCONTROL should remove ignorespace" {
@test "__bp_adjust_histcontrol should remove ignorespace and ignoreboth" {

# Should remove ignorespace
HISTCONTROL="ignorespace:ignoredups:*"
HISTCONTROL="${HISTCONTROL//ignorespace}"
__bp_adjust_histcontrol
[[ "$HISTCONTROL" == ":ignoredups:*" ]]

# Should remove ignoreboth and replace it with ignoredups
HISTCONTROL="ignoreboth"
__bp_adjust_histcontrol
[[ "$HISTCONTROL" == "ignoredups:" ]]

# Handle a few inputs
HISTCONTROL="ignoreboth:ignorespace:some_thing_else"
__bp_adjust_histcontrol
echo "$HISTCONTROL"
[[ "$HISTCONTROL" == "ignoredups:::some_thing_else" ]]

}

0 comments on commit 7e55ac1

Please sign in to comment.