Skip to content
Open
Show file tree
Hide file tree
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
7 changes: 6 additions & 1 deletion scripts/main.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ source "./utils/clipboard.sh"
source "./utils/cmd.sh"
source "./utils/op.sh"
source "./utils/prompt.sh"
source "./utils/recent.sh"
source "./utils/semver.sh"
source "./utils/spinner.sh"
source "./utils/tmux.sh"
Expand All @@ -20,6 +21,7 @@ source "./options.sh"
main() {
local -r ACTIVE_PANE="$1"

local op_items
local items
local selected_item
local selected_item_name
Expand All @@ -45,7 +47,8 @@ main() {
fi

spinner::start "Fetching items"
items="$(op::get_all_items)"
op_items="$(op::get_all_items)"
items=$(recent::get_all_items "$op_items")
spinner::stop

synchronize_panes_reset_value=$(tmux::disable_synchronize_panes)
Expand Down Expand Up @@ -78,6 +81,8 @@ main() {
;;
esac

recent::add "$selected_item_name"

if options::copy_to_clipboard; then

# Copy password to clipboard
Expand Down
47 changes: 47 additions & 0 deletions scripts/utils/recent.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#!/usr/bin/env bash

# ------------------------------------------------------------------------------

declare -r OP_RECENT_FILE=~/.op_tmux_recent

recent::file() {
echo "${OP_RECENT_FILE}_$(options::op_account)"
}

recent::add() {
local recent=$(tmux::get_option "@1password-recent" "0")
local recents

if [[ $recent -eq 0 ]]; then
rm -f "$(recent::file)"
else
echo $1 >> "$(recent::file)"
recents=$(cat "$(recent::file)")
echo "$recents" | tac | awk '!seen[$0]++' | tac | tail -n $recent > "$(recent::file)"
fi
}

recent::get() {
local recent=$(tmux::get_option "@1password-recent" "0")

if [[ $recent -eq 0 ]]; then
rm -f "$(recent::file)"
elif [ -f "$(recent::file)" ]; then
cat "$(recent::file)" | tac
fi
}

recent::get_all_items() {
local op_items="$1"
local recent_item
local rencent_items=$(recent::get)

if ! [[ -z "$rencent_items" ]]; then
while IFS= read recent_item; do
echo $(echo "$op_items" | grep "^$recent_item,")
op_items=$(echo "$op_items" | grep -v "^$recent_item,")
done <<< "$(echo -e "$rencent_items")"
fi

echo "$op_items"
}