Skip to content

Instantly share code, notes, and snippets.

@ngregoire

ngregoire/.zshrc

Last active Apr 6, 2020
Embed
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 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