blob: bf7b443ace8eca3c9cb4f82966680acb31f61f8f (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
|
#!/usr/bin/env bash
set -euo pipefail
RED="\e[31m" GREEN="\e[32m" RESET="\e[0m"
msg() {
case "$1" in
error)
printf '%b\n' "${RED}$2${RESET}"
bash -c -- read -n 1 -s -r
;;
done)
printf '%b\n' "${GREEN}$2${RESET}"
bash -c -- read -n 1 -s -r
;;
esac
}
current_shell=$(getent passwd "$USER" | cut -d: -f7 | xargs basename)
fzf_opts=(
"--height=50%"
"--border"
"--layout=reverse"
)
if [ "$current_shell" == "bash" ]; then
# Get the history file path
if [ -s "$HOME/.local/share/bash/history" ]; then
history_file="$HOME/.local/share/bash/history"
elif [ -s "$HOME/.bash_history" ]; then
history_file="$HOME/.bash_history"
fi
# Check if the history file exists and is not empty
if [ -s "$history_file" ]; then
cat "$history_file" |
fzf "${fzf_opts[@]}" |
wl-copy ||
msg error "Nothing selected to copy"
else
msg error "No history found"
fi
elif [ "$current_shell" == "zsh" ]; then
# Get the history file path
if [ -s "$HOME/.zsh_history" ]; then
history_file="$HOME/.zsh_history"
elif [ -s "$HOME/.local/share/zsh/history" ]; then
history_file="$HOME/.local/share/zsh/history"
fi
# Check if the history file exists and is not empty
if [ -n "$history_file" ]; then
cat "$history_file" |
cut -d';' -f2 |
fzf "${fzf_opts[@]}" |
wl-copy ||
msg error "Nothing selected to copy"
else
msg error "No history found"
fi
fi
|