Skip to content

Instantly share code, notes, and snippets.

@lorens-osman-dev
Created November 11, 2024 01:25
Show Gist options
  • Save lorens-osman-dev/a169bc856bdbea4bdc8ac8df0e7de785 to your computer and use it in GitHub Desktop.
Save lorens-osman-dev/a169bc856bdbea4bdc8ac8df0e7de785 to your computer and use it in GitHub Desktop.
fish useful commands
#--------|[ Useful Commands ]|--------#
function useful_commands
# Set the commands file path as a universal variable so it's accessible in preview
set -x commands_file "$HOME/lorens_linux_config/zsh/usefull_commands.txt"
set header "CommandsList"
# Define fzf options as an array
set fzf_cool \
--reverse \
--pointer="➜" \
--info=inline-right \
--height 40% \
--no-separator \
--preview-window=down,20%,wrap \
--color='dark,hl:red:regular,fg+:white:regular,hl+:red:regular:reverse,query:white:regular,info:#cb4b16,prompt:#dd4814:bold,pointer:#dd4814:bold'
switch "$argv[1]"
case "file"
echo "Commands List file path is: $commands_file"
zed -i "$commands_file"
case "add"
echo "Commands List file path is: $commands_file"
zed "$commands_file"
case '*'
set selected_command (grep -v '^$' "$commands_file" \
| grep -v '^#' \
| sed -e 's/^[ \t]*//' \
| grep -v '^\*\*' \
| fzf $fzf_cool \
--preview "echo -e \"\033[32m\$(grep -xF -B1 {} \"$commands_file\" | sed \"s/^**/*/\"| head -1)\033[0m\"")
# In fish, we use 'commandline' instead of print -z
if test -n "$selected_command"
commandline -r -- $selected_command
#commandline -f execute
end
end
end
# Create the alias
alias uc "useful_commands"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment