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