Skip to content

Instantly share code, notes, and snippets.

@cirrusUK
Created Oct 5, 2021
Embed
What would you like to do?
#!/bin/bash
################################################################
# rf
# open files, cd into directories and stuff
# not the most intuitively written bash script but it werks hehe
# made by theo
################################################################
export opener="piper"
# export opener="rifle" (i use rifle, so)
fzf="fzf -e --tac --reverse --border=sharp --ansi --color=bg+:#073642,bg:#002b36,spinner:#719e07,hl:#586e75 --color=fg:#839496,header:#586e75,info:#cb4b16,pointer:#719e07 --color=marker:#719e07,fg+:#839496,prompt:#719e07,hl+:#719e07 --border=sharp --prompt=➤ --pointer=➤ --marker=➤ "
################################################################
depcheck() {
if [[ -z $(command -v fzf) ]]; then
printf "install fzf.\
\nfzf is required for this script to function."\
&& exit 0; fi;}
################################################################
displayhelp() {
printf "
rf: open files, cd into directories and stuff
using find and fzf.
usage: rf [options]
OPTIONS
=> no arguments \n\t open files via \$opener. (rifle is set as default)
=> -l \n\t open files but don't close fzf.
=> -d \n\t open directories in a subshell.
=> -h / --help \n\t display help text.
=> -z \n\t search for files and open the directory in which they are located.\n\n";}
################################################################
depcheck
################################################################
case $1 in
"") find / -type f 2>/dev/null | $fzf --bind=enter:execute'($opener {})' --bind=enter:+close ;;
-l) find / -type f 2>/dev/null | $fzf --bind=enter:execute'($opener {})' ;;
-d) folder="$(find / -type d 2>/dev/null | $fzf)" && cd "$folder" && \
echo "Press Ctrl+d to exit the subshell" && $SHELL ;;
-h|--help) displayhelp ;;
-z) folder="$(find / -type f 2>/dev/null | $fzf)" && \
cd "$(dirname $folder)" && \
echo "Press Ctrl+d to exit the subshell" && $SHELL ;;
esac
################################################################
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment