@@ -4,6 +4,7 @@ use regex::Regex;
44use rodio:: { OutputStream , Sink , Source } ;
55use std:: collections:: HashMap ;
66use std:: env;
7+ use clipboard:: { ClipboardContext , ClipboardProvider } ;
78use std:: fs:: { self , File } ;
89use std:: io:: { self , Error , Read , Write } ;
910use std:: path:: Path ;
@@ -1398,6 +1399,42 @@ impl Executor {
13981399 } )
13991400 }
14001401
1402+ // Set value in the clipboard
1403+ "set-clipboard" => {
1404+ let mut ctx: ClipboardContext ;
1405+ if let Ok ( i) = ClipboardProvider :: new ( ) {
1406+ ctx = i
1407+ } else {
1408+ self . stack . push ( Type :: Error ( "set-clipboard" . to_string ( ) ) ) ;
1409+ return
1410+ } ;
1411+
1412+ let value = self . pop_stack ( ) . get_string ( ) ;
1413+ if ctx. set_contents ( value. clone ( ) ) . is_ok ( ) {
1414+ self . stack . push ( Type :: String ( value) ) ;
1415+ } else {
1416+ self . stack . push ( Type :: Error ( "get-clipboard" . to_string ( ) ) )
1417+ } ;
1418+ }
1419+
1420+ // Get value in the clipboard
1421+ "get-clipboard" => {
1422+ let mut ctx: ClipboardContext ;
1423+ if let Ok ( i) = ClipboardProvider :: new ( ) {
1424+ ctx = i
1425+ } else {
1426+ self . stack . push ( Type :: Error ( "set-clipboard" . to_string ( ) ) ) ;
1427+ return
1428+ } ;
1429+
1430+
1431+ if let Ok ( contents) = ctx. get_contents ( ) {
1432+ self . stack . push ( Type :: String ( contents) ) ;
1433+ } else {
1434+ self . stack . push ( Type :: Error ( "get-clipboard" . to_string ( ) ) )
1435+ }
1436+ }
1437+
14011438 // If it is not recognized as a command, use it as a string.
14021439 _ => self . stack . push ( Type :: String ( command) ) ,
14031440 }
0 commit comments