Skip to content

Instantly share code, notes, and snippets.



Last active Apr 6, 2020
What would you like to do?
Efficiently open files from the CLI (using xdg-open and fasd)
# Add this line to your .bashrc / .zshrc
# The 'o' script (cf below) must be in your $PATH
# 'fasd' (cf must be in your $PATH too
alias oo='fasd -a -e o'
# Now use 'oo criteria<TAB>' (iterate through matches) or simply 'oo' (list entries)
# Given that 'fasd' is a requirement, maybe have a look at the 'zz' alias
# Take n arguments (files / directories)
# Open them in their default app
# A properly configured XDG db is needed, cf ~/bin/xdg (cf below)
if [ $# -eq 0 ]; then
xdg-open . &> /dev/null
for file in "$@"; do
xdg-open "$file" &> /dev/null
# Take a single argument (file / directory)
# Display the corresponding mimetype and default app
# Used to configure the XDG database
if [ -z "$1" ]; then
echo "Argument is needed!"
MIMETYPE=`xdg-mime query filetype $1`
HANDLER=`xdg-mime query default $MIMETYPE`
echo "Type '$MIMETYPE' is handled by '$HANDLER'"
echo "Map it to 'gvim' with the following command:"
echo "xdg-mime default gvim.desktop $MIMETYPE"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment