Skip to content

Commit

Permalink
Try to exclude commands that might contain a password (specify a user…
Browse files Browse the repository at this point in the history
…name).
  • Loading branch information
jimlawton committed Jan 31, 2016
1 parent d3fe9d7 commit 8bc9b48
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions functions
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,17 @@ function find.name() {
sh -c "find . -iname $wild"
}

# Function that takes 2 args, a list and a string,
# and returns 0 if the string is in the list, or
# 1 otherwise.
function contains() {
for item in $1; do
if [ "$item" = "$2" ]; then
return 0
fi
done
return 1
}

# From Eli Bendersky
# http://eli.thegreenplace.net/2013/06/11/keeping-persistent-history-in-bash/
Expand All @@ -253,6 +264,16 @@ function log_bash_persistent_history() {
[[ $(history 1) =~ ^\ *[0-9]+\ +([^\ ]+\ [^\ ]+)\ +(.*)$ ]]
local date_part="${BASH_REMATCH[1]}"
local command_part="${BASH_REMATCH[2]}"
# Try to replace usernames/passwords.
if contains "$command_part" "$USER"; then
return
fi
if contains "$command_part" "jiml"; then
return
fi
if contains "$command_part" "jlawton"; then
return
fi
if [ "$command_part" != "$PERSISTENT_HISTORY_LAST" ]; then
echo "$HOSTNAME | $date_part | $command_part" >> ~/.persistent_history
export PERSISTENT_HISTORY_LAST="$command_part"
Expand Down

0 comments on commit 8bc9b48

Please sign in to comment.