Improve some windows aliases
This commit is contained in:
parent
3cad6ed0da
commit
a82694311a
75
aliases
75
aliases
|
@ -56,14 +56,72 @@ update-shell() {
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
remove_windows_file() {
|
# Will return a symlink path in its expanded form. If the path's root is the
|
||||||
if [ -f "$1" ]; then
|
# home directory symbol "~" then it'll be replaced by the full home path.
|
||||||
recycle-bin.exe "$1"
|
expand_path() {
|
||||||
elif [ -d "$1" ]; then
|
local ret="$1"
|
||||||
recycle-bin.exe "$1"
|
|
||||||
else
|
IFS="/" read -ra parts <<< "$ret"
|
||||||
echo "'$1' does not exist!"
|
if [[ "${parts[0]}" == "~" ]]; then
|
||||||
|
ret="$HOME"
|
||||||
|
for ((i=1; i < ${#parts[@]}; i++))
|
||||||
|
do
|
||||||
|
ret="$ret/${parts[$i]}"
|
||||||
|
done
|
||||||
fi
|
fi
|
||||||
|
ret=$(readlink -m "$ret")
|
||||||
|
echo $ret
|
||||||
|
}
|
||||||
|
is_absolute_unix_path() {
|
||||||
|
if [[ $1 =~ ^/ ]]; then echo 1; else echo 0; fi
|
||||||
|
}
|
||||||
|
|
||||||
|
is_windows_path() {
|
||||||
|
if [[ ! $1 =~ \/+ ]]; then echo 1; else echo 0; fi
|
||||||
|
}
|
||||||
|
|
||||||
|
# Returns a Unix path with spaces escaped with a '\'.
|
||||||
|
escape_unix_path() {
|
||||||
|
ret="$1"
|
||||||
|
ret="${ret/ /\\ }"
|
||||||
|
echo "$ret"
|
||||||
|
}
|
||||||
|
|
||||||
|
# Returned value does not have a trailing '\'.
|
||||||
|
unix_to_windows_path() {
|
||||||
|
ret="$1"
|
||||||
|
if [[ $(is_windows_path "$ret") -eq 0 ]]; then
|
||||||
|
if [[ $(is_absolute_unix_path "$ret") -eq 1 ]]; then
|
||||||
|
ret="${ret/\//}"
|
||||||
|
# Fix the drive name, e.g. c\foo becomes c:\foo
|
||||||
|
ret=$(sed 's,\([a-zA-Z]*\),\1:,' <<< "$ret")
|
||||||
|
fi
|
||||||
|
ret="${ret////\\}" # Replace Unix slashes.
|
||||||
|
ret="${ret//\\\(/\(}" # Remove backslash before (.
|
||||||
|
ret="${ret//\\\)/\)}" # Remove backslash before ).
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Strip trailing slashes.
|
||||||
|
shopt -s extglob
|
||||||
|
ret=$(echo "${ret%%+(\\)}")
|
||||||
|
|
||||||
|
echo $ret
|
||||||
|
}
|
||||||
|
|
||||||
|
remove_windows_file() {
|
||||||
|
local path=$(expand_path "$1")
|
||||||
|
if [[ -f "$path" || -d "$path" ]]; then
|
||||||
|
local dest=$(unix_to_windows_path "$path")
|
||||||
|
recycle-bin.exe $dest
|
||||||
|
else
|
||||||
|
echo "'$path' does not exist!"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
open_explorer_here() {
|
||||||
|
local path_expanded=$(expand_path "$1")
|
||||||
|
local path=$(unix_to_windows_path "$path_expanded")
|
||||||
|
explorer.exe "$path"
|
||||||
}
|
}
|
||||||
|
|
||||||
make_vid_dir_and_cd_into() {
|
make_vid_dir_and_cd_into() {
|
||||||
|
@ -497,7 +555,8 @@ alias cpr='cp -r'
|
||||||
alias dc='gdc'
|
alias dc='gdc'
|
||||||
alias dot='cd ~/.dotfiles'
|
alias dot='cd ~/.dotfiles'
|
||||||
alias duh='du -csh'
|
alias duh='du -csh'
|
||||||
alias exp='explorer .'
|
alias exp='open_explorer_here "$PWD"'
|
||||||
|
|
||||||
alias f='fg'
|
alias f='fg'
|
||||||
|
|
||||||
####################################################################################################
|
####################################################################################################
|
||||||
|
|
Loading…
Reference in New Issue
Block a user