Last active
April 6, 2020 18:04
-
-
Save ngregoire/aa2aa4145aa47206974f35bc5374ce0d to your computer and use it in GitHub Desktop.
Efficiently open files from the CLI (using xdg-open and fasd)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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