Xu Xiaodong avatar Xu Xiaodong committed ebd5d38

minor update

Comments (0)

Files changed (1)

 use strict;
 use warnings;
 
-my $cmd  = 'xrandr';        # 设置命令
-my $mode = '1280x768';      # 要设置的分辨率大小
-my $out  = get_out($cmd);
+use Tie::File;
+
+my $cmd  = 'xrandr';         # 设置命令
+my $mode = '1280x768';       # 要设置的分辨率大小
+my $out  = get_out($cmd);    # 已连接的显示器
 
 set_res( $cmd, $out, $mode );
 
   my $addmode = qq{$cmd --addmode $out $mode};
   my $setmode = qq{$cmd --output $out --mode $mode};
 
-  open my $out_fh, '>', "$ENV{HOME}/.xprofile"
-    or die "Can't write .xprofile: $!\n";
+  my $file = "$ENV{HOME}/.xprofile";
 
-  print $out_fh $newmode, "\n";
+  tie my @lines, 'Tie::File', $file
+    or die "Can't read '$file': $!\n";
+
+  push @lines, $newmode . "\n";
+  push @lines, $addmode . "\n";
+  push @lines, $setmode . "\n";
+
+  untie @lines;
+
   system $newmode;
-  print $out_fh $addmode, "\n";
   system $addmode;
-  print $out_fh $setmode, "\n";
   system $setmode;
-
-  close $out_fh;
 }
 
 #
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.