Mac卸载Pandoc

在用Typora导出word时提示需要安装Pandoc,Pandoc有两种安装方式,第一种是通过安装器安装
在这里插入图片描述
第二种方式是使用brew

brew install pandoc

但如果你使用第一种方式安装了,但想卸载了使用第二种方式安装,该怎么卸载呢?

#!/usr/bin/perl

# Script to remove all files installed by the macOS pandoc installer
# and unregister the package.  Modified from a script contributed
# by Daniel T. Staal.

use warnings;
use strict;

use File::Spec;

# The main info: this is the list of files to remove and the pkg_id.
my $pkg_id    = 'net.johnmacfarlane.pandoc';

# Find which, if any, volume Pandoc is installed on.
my $volume;

# First check /, then other volumes on the box.
my $cur_test = `pkgutil --pkgs=$pkg_id`;
if ( $cur_test =~ m/$pkg_id/ ) {
    $volume = '/';
} else {
    opendir( my $dh, '/Volumes' ) or die "Can't list Volumes: $!\n";
    foreach my $dir ( readdir($dh) ) {
      next if $dir =~ m/^\./;    # Skip dotfiles.

      my $path = File::Spec->rel2abs( $dir, '/Volumes' );
      next if !( -d $path );     # Skip anything that isn't a directory.

      my $cur_test = `pkgutil --pkgs=$pkg_id --volume '$path'`;
      if ( $cur_test =~ m/$pkg_id/ ) {
          $volume = $path;
          last;
      }
    }
}

die "Pandoc not installed.\n" if !( defined($volume) );

# Get the list of files to remove.
my @pkg_files = `pkgutil --volume '$volume' --only-files --files '$pkg_id'`;
@pkg_files = map { chomp; File::Spec->rel2abs($_, $volume) } @pkg_files;

# Confirm uninistall with the user.
print "The following files will be deleted:\n\n";
print join("\n", @pkg_files);
print "\n\n";
print "Do you want to proceed and uninstall pandoc (Y/N)?";
my $input = <STDIN>;

if ($input =~ m/^[Yy]/) {

    # Actually remove the files.
    foreach my $file (@pkg_files) {
        if ( -e $file ) {
            if ( system( 'sudo', 'rm', $file ) == 0 ) {
                warn "Deleted $file\n";
            } else {
                warn "Unable to delete $file: $?\n";
                die "Aborting Uninstall.\n";
            }
        }  else {
            warn "File $file does not exist.  Skipping.\n";
        }
    }

    # Clean up the install.
    if (system('sudo', 'pkgutil', '--forget', $pkg_id, '--volume', $volume) != 0) {
        die "Unable to clean up install: $?\n";
    }

} else {

   print "OK, aborting uninstall.\n";
   exit;
}

print "Pandoc has been successfully uninstalled.\n";
exit;

将上面的代码保存在uninstall-pandoc.pl里

perl uninstall-pandoc.pl
The following files will be deleted:

/._usr
/usr/._local
/usr/local/._bin
/usr/local/._share
/usr/local/bin/._pandoc
/usr/local/bin/pandoc
/usr/local/share/._man
/usr/local/share/man/._man1
/usr/local/share/man/man1/._pandoc.1
/usr/local/share/man/man1/pandoc.1

Do you want to proceed and uninstall pandoc (Y/N)?

不得不说Homebrew真香

参考:
https://pandoc.org/installing.html#macos
https://imonce.github.io/2018/09/28/Mac%E5%A6%82%E4%BD%95%E5%8D%B8%E8%BD%BDpandoc/

  • 4
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值