From 9496c2c10308ce934bc1cba9bf7887f5f55a5e5b Mon Sep 17 00:00:00 2001 From: Ivan Malison Date: Sat, 18 Mar 2017 10:46:45 -0700 Subject: [PATCH] [Linux] Extend rofi_command to include aliases and functions --- dotfiles/lib/bin/rofi_command.sh | 30 ++++++++++++++++++++++++------ 1 file changed, 24 insertions(+), 6 deletions(-) diff --git a/dotfiles/lib/bin/rofi_command.sh b/dotfiles/lib/bin/rofi_command.sh index b5dc5a1a..240e401e 100755 --- a/dotfiles/lib/bin/rofi_command.sh +++ b/dotfiles/lib/bin/rofi_command.sh @@ -1,11 +1,29 @@ -#!/usr/bin/env bash -function get_all_commands { - IFS=: - for exec_path in $PATH; do +#!/usr/bin/env zsh + +get_all_executables () { + for exec_path in $path; do test -r "$exec_path" && \ find "$exec_path" -maxdepth 1 -executable ! -type d -printf "%f\n" done } -selected=$(get_all_commands | rofi -dmenu -i) -"$selected" +get_all_functions () { + print -l ${(ok)functions} +} + +get_all_aliases () { + alias | cut -d = -f 1 +} + + +selected=$({ get_all_executables; get_all_aliases; get_all_functions; } | rofi -dmenu -i -kb-custom-1 "Alt+c") +rofi_exit="$?" +args="" +case "$rofi_exit" in + 1) + exit + ;; + 10) + args=$(echo "" | rofi -dmenu) +esac +eval "$selected $args"