Cygwin/MSYS2文件夹书签功能函数,调用Windows资源管理器快速打开文件夹;

2022/3/27 7:24:30

本文主要是介绍Cygwin/MSYS2文件夹书签功能函数,调用Windows资源管理器快速打开文件夹;,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

favorite-dirs函数

如需使用第三方软件或插件打开文件夹路径,只需替换代码中的explorer.exe为第三方软件可执行文件名即可,比如可以替换成total commander等软件的可执行程序;(注意可能需要填写软件程序的完整路径),

favorite-dirs() {
	#使用资源管理器快速打开Windows系统常用文件夹
	local mydirs=$(cat<<EOF
	Shell:downloads
	Shell:documents
	Shell:Sendto
	Shell:Quick Launch
	Shell:AppData
	%LocalAppdata%
	Shell:startup
	Shell:common startup
	Shell:programfiles
	Shell:programfilesx86
	%UserProfile%
	%UserProfile%\.ssh
	Shell:ProgramFiles\git
	Shell:ProgramFiles\git\etc
	Shell:AppData\Google
	Shell:programfilesx86\NetSarang
	D:\MySelf\shell-scripts
	D:\Work\Documents
EOF
)
	#输出选择菜单:
	echo "$mydirs"|awk '{printf NR"): ";print}'
	while :;
	do
		read -p "请输入序号选择,可一次性输入多个选项[用空格隔开](输入 0 退出选择,输入 p 再次打印目录选项):" dirChoose
		if [ ! -z "$dirChoose" ];then
			if [[ "${dirChoose,,}" == "p" ]];then
				echo "$mydirs"|awk '{printf NR"): ";print}'
				continue
			fi
			if [[ "$dirChoose" == "0" ]];then
				echo "exit..."
				break
			fi
			open-single-dir() {
				#local targetDir=$(echo "$mydirs"|awk "NR==$dirChoose"'{gsub(/^\s*/,"");print;exit}')
				local targetDir=$(echo "$mydirs"|awk "NR==$1"'{gsub(/^\s*/,"");print;exit}')
				if [ ! -z "$targetDir" ];then
					echo "Open Dir $targetDir ..."
					cmd /c explorer.exe "$targetDir "
				else
					echo "targetDir is empty!"
				fi
			}
			mapfile -t -d $' ' myDirArr<<<"$dirChoose"
			
			for dir in ${myDirArr[@]};
			do 
				#echo "open dir:$dir"
				open-single-dir $dir
			done			
		else
			echo "Have No Choice...!"
		fi
	done
}
alias mydirs='favorite-dirs'
alias d3='favorite-dirs'



这篇关于Cygwin/MSYS2文件夹书签功能函数,调用Windows资源管理器快速打开文件夹;的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!


扫一扫关注最新编程教程