简体   繁体   English

OS X Shell-'Clickable'脚本删除文件?

[英]OS X Shell - 'Clickable' script to erase files?

I use Latex to write my documents. 我用Latex来写文件。 Latex creates MANY auxiliary files to compile a document. Latex创建许多辅助文件来编译文档。 I often times want to clean my working directory. 我经常想清理我的工作目录。

While I worked on Windows, I used to keep a .bat file in the working directory that looked like this: 在Windows上工作时,我通常将.bat文件保存在工作目录中,如下所示:

del *.aux
del *.pdf
del *.log
del *.bak
del *.gz
del *.bbl
del *.blg

which I could just click on to get rid of all auxiliary files in the current directory . 我可以单击以摆脱当前目录中的所有辅助文件。

Now, I want to do the same on my Mac. 现在,我想在Mac上执行相同的操作。 I have created a .sh file like this: 我已经创建了一个.sh文件,如下所示:

#!/bin/bash

echo "Cleaning files..."

rm *.aux
rm *.bak
rm *.bbl
rm *.blg
rm *.gz
rm *.log
rm *.pdf

echo "Done!"

which I know I can run (ie invoke from command line), but I cannot click on - which is more convenient because not always I will be using Terminal. 我知道我可以运行(即从命令行调用),但是我无法单击-这更方便,因为并非总是使用终端。

I should stress the fact that the script should delete the files in the directory where it was clicked from! 我要强调一个事实,脚本应该删除单击它的目录中的文件!

How can I convert this script into a "clickable" one? 如何将该脚本转换为“可点击的”脚本?

I appreciate any input! 感谢您的投入!

Based on this reference ( Getting the source directory of a Bash script from within ), I ended up solving my problem with the following code: 基于此参考( 从内部获取Bash脚本的源目录 ),我最终使用以下代码解决了我的问题:

#!/bin/bash

DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )

echo "Cleaning files..."

cd $DIR
rm *.aux
rm *.bak
rm *.bbl
rm *.blg
rm *.gz
rm *.log
rm *.pdf

echo "Done!"

#read -p "Press [Enter] to continue..."

It works very well to clean all the nasty files left behind by Texmaker! 它非常适合清除Texmaker留下的所有令人讨厌的文件!

请参见此答案以使Shell脚本可双击,但请注意,从Finder启动脚本时,没有“当前目录”的概念。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM