Skip to content

Instantly share code, notes, and snippets.

@ngregoire
Last active April 6, 2020 18:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ngregoire/aa2aa4145aa47206974f35bc5374ce0d to your computer and use it in GitHub Desktop.
Save ngregoire/aa2aa4145aa47206974f35bc5374ce0d to your computer and use it in GitHub Desktop.
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 https://github.com/clvv/fasd) 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
#!/bin/bash
# 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
else
for file in "$@"; do
xdg-open "$file" &> /dev/null
done
fi
#!/bin/bash
# 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!"
exit
else
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"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment