Skip to content

Instantly share code, notes, and snippets.

@umezo
Created September 18, 2012 07:14
Show Gist options
  • Save umezo/3741739 to your computer and use it in GitHub Desktop.
Save umezo/3741739 to your computer and use it in GitHub Desktop.
convert path between ms shared folder and samba url
function convert_smb_url() {
local file_path=''
if [ -n "$1" ] ; then
file_path=$1
else
file_path=`print -R $(pbpaste)`
fi
if [ -n $file_path ] ; then
local prefix=`echo $1|egrep "^smb://" -o`
local direction=''
local sed1=''
local sed2=''
print -R convert $file_path
# case samba to win
if [ -n "$prefix" ] ; then
direction="mac–>win"
sed1='s/\//\\/g'
sed2='s/smb://'
# case win to samba
else
direction="win->mac"
sed1='s/\\/\//g'
sed2='s/^/smb:/'
fi
#echo $direction
#print -R "$file_path" | sed -e "$sed1" -e "$sed2"
print -R "$file_path" | sed -e "$sed1" -e "$sed2" | pbcopy
#print convert result will be copied into clipboard
fi
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment