Skip to content

Instantly share code, notes, and snippets.

@lorens-osman-dev
Created September 27, 2024 20:46
Show Gist options
  • Save lorens-osman-dev/b3b23354065eef21526dd48f65bab232 to your computer and use it in GitHub Desktop.
Save lorens-osman-dev/b3b23354065eef21526dd48f65bab232 to your computer and use it in GitHub Desktop.
#--------|[ Explorer ]|--------#
e(){
if [ -z $1 ]; then
nautilus .
else
nautilus $1
fi
}
#--------|[ n() function ]|--------#
n(){
if [ -z $1 ]; then
echo "There is no file to open"
else
gnome-text-editor $1
fi
}
alias note="n"
#--------|[ neat_explorer ]|--------#
#When you use the "cd" command without any additional information, it will automatically
#take you to your home directory. The purpose of the "cd()" function is to cancel this behavior.
#Note cd() invoked in neat_explorer()
#Note before cd() was not function word , we added it to test,
#when we add it the reload works perfectly but neat_explorer() doesn't work after reload , if we remove it reload doesn't works but
# neat_explorer() works
function cd() {
[[ $# -eq 0 ]] && return
builtin cd "$@"
}
# n() notepad
function neat_explorer() {
# --border-label=lorens is unnecessary with fzf `header` option
info_inline_separator=']'
fzf_cool=(
--reverse
--border=sharp
--height 40%
--info=inline:$info_inline_separator
--separator=""
--prompt="[ "
--pointer="→"
--color=fg:#839496,bg+:#242424,spinner:#719e07,hl+:#5fff87,disabled:#ce392c
--color=header:#586e75,info:#cb4b16,pointer:#5fff87
--color=marker:#719e07,fg+:#839496,prompt:#5fff87,hl:#719e07
)
cd "$1"
if [[ -z "$1" ]]; then
selection="$(exa --tree --level=1 --group-directories-first --icons -a | fzf --header="$(pwd)" "$fzf_cool[@]" )"
if [[ "${#selection}" -gt 6 ]]; then
new_selection="${selection:6}"
if [[ -d "$new_selection" ]]; then
cd "$new_selection" && neat_explorer
elif [[ -f "$new_selection" ]]; then
n "$new_selection"
fi
elif [[ "${#selection}" -eq 3 ]]; then
new_selection="${selection:1}"
cd .. && neat_explorer
else
echo ""
fi
fi
}
alias cd="neat_explorer"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment