Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nextspace command line tools #337

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 59 additions & 0 deletions Tools/GNUmakefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
#
# Tools makefile for NX Tools
# Copyright (C) 2020 Free Software Foundation, Inc.
#
# Written by: onflapp
#
# This file is part of the NEXTSPACE project.
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public
# License as published by the Free Software Foundation; either
# version 2 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public
# License along with this library; if not, write to the Free
# Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
# Boston, MA 02111 USA.

ifeq ($(GNUSTEP_MAKEFILES),)
GNUSTEP_MAKEFILES := $(shell gnustep-config --variable=GNUSTEP_MAKEFILES 2>/dev/null)
ifeq ($(GNUSTEP_MAKEFILES),)
$(warning )
$(warning Unable to obtain GNUSTEP_MAKEFILES setting from gnustep-config!)
$(warning Perhaps gnustep-make is not properly installed,)
$(warning so gnustep-config is not in your PATH.)
$(warning )
$(warning Your PATH is currently $(PATH))
$(warning )
endif
endif

ifeq ($(GNUSTEP_MAKEFILES),)
$(error You need to set GNUSTEP_MAKEFILES before compiling!)
endif

PACKAGE_NAME = nxtools

include $(GNUSTEP_MAKEFILES)/common.make

# Manual pages to install
MAN1_PAGES = nxworkspace.1 nxpasteboard.1

# The application to be compiled
TOOL_NAME = nxworkspace nxpasteboard

# The source files to be compiled
nxworkspace_OBJC_FILES = nxworkspace.m
nxpasteboard_OBJC_FILES = nxpasteboard.m

include GNUmakefile.preamble

include $(GNUSTEP_MAKEFILES)/tool.make

include GNUmakefile.postamble
79 changes: 79 additions & 0 deletions Tools/GNUmakefile.postamble
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
# -*-makefile-*-
#
# Makefile.postamble
#
# Copyright (C) 2005, Free Software Foundation, Inc.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either
# version 2 of the License, or (at your option) any later version.
# This program is distributed in the
# hope that it will be useful, but WITHOUT ANY WARRANTY; without even
# the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
# PURPOSE. See the GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
#
# Project specific makefile rules
#
# Uncomment the targets you want.
# The double colons (::) are important, do not make them single colons
# otherwise the normal makefile rules will not be performed.
#

# Things to do before compiling
# before-all::

# Things to do after compiling
# after-all::

# Things to do before installing
before-install::

# Things to do after installing
after-install::
if [ ! -f $(GNUSTEP_SYSTEM_DOC_MAN) ]; then \
$(MKDIRS) $(GNUSTEP_SYSTEM_DOC_MAN); \
fi; \
if [ ! -f $(GNUSTEP_SYSTEM_DOC_MAN)/man1 ]; then \
$(MKDIRS) $(GNUSTEP_SYSTEM_DOC_MAN)/man1; \
fi; \
for file in $(MAN1_PAGES) __done; do \
if [ $$file != __done ]; then \
$(INSTALL_DATA) $$file $(GNUSTEP_SYSTEM_DOC_MAN)/man1/$$file; \
which gzip && rm -f $(GNUSTEP_SYSTEM_DOC_MAN)/man1/$$file.gz \
&& gzip -9 $(GNUSTEP_SYSTEM_DOC_MAN)/man1/$$file; \
fi; \
done; \

# Things to do before uninstalling
before-uninstall::
for file in $(MAN1_PAGES); do \
rm -f $(GNUSTEP_SYSTEM_DOC_MAN)/man1/$$file.gz; \
done;
-rmdir $(GNUSTEP_SYSTEM_DOC_MAN)/man1;

# Things to do after uninstalling
# after-uninstall::

# Things to do before cleaning
# before-clean::

# Things to do after cleaning
# after-clean::

# Things to do before distcleaning
# before-distclean::

# Things to do after distcleaning
# after-distclean::

# Things to do before checking
# before-check::

# Things to do after checking
# after-check::

59 changes: 59 additions & 0 deletions Tools/GNUmakefile.preamble
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
#
# Tools makefile for nxtools
#
# Copyright (C) 2020 Free Software Foundation, Inc.
#
# This file is part of the NEXTSPACE project
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public
# License as published by the Free Software Foundation; either
# version 2 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public
# License along with this library; if not, write to the Free
# Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
# Boston, MA 02111 USA.
#

# Makefile.preamble
#
# Project specific makefile variables, and additional
#
# Do not put any Makefile rules in this file, instead they should
# be put into Makefile.postamble.
#

#
# Flags dealing with compiling and linking
#

# Additional flags to pass to the preprocessor
#ADDITIONAL_CPPFLAGS +=

# Additional flags to pass to the Objective-C compiler
#ADDITIONAL_OBJCFLAGS +=

# Additional flags to pass to the C compiler
#ADDITIONAL_CFLAGS +=

# Additional include directories the compiler should search
#ADDITIONAL_INCLUDE_DIRS +=

# Additional LDFLAGS to pass to the linker
ADDITIONAL_LDFLAGS += -lgnustep-gui

# Additional library directories the linker should search
#ADDITIONAL_LIB_DIRS +=

#
# Flags dealing with installing and uninstalling
#

# Additional directories to be created during installation
#ADDITIONAL_INSTALL_DIRS +=
36 changes: 36 additions & 0 deletions Tools/nxpasteboard.1
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
.\"nxpasteboard(1) man page
.\"put together by onflapp
.\"Copyright (C) 2020 Free Software Foundation, Inc.
.\"Copying and distribution of this file, with or without modification,
.\"are permitted in any medium without royalty provided the copyright
.\"notice and this notice are preserved.
.\"
.\"Process this file with
.\"groff -man -Tascii nxpasteboard.1
.\"
.TH NXPASTEBOARD 1 "August 2020" GNUstep "NEXTSPACE System Manual"
.SH NAME
nxpasteboard \- gives you ability to do copy & paste and invoke system services directly from command line
.SH SYNOPSIS
.B nxpasteboard [--copy] [--paste] [--service <name>]
.P
.SH DESCRIPTION
.P
copy reads text from the stantard input and writes it to the pasteboard
.P
paste reads text from the pasteboard and writes it to the standard output
.P
service reads text from the standard input and then calls system service to process it. System service is indentified by its name. This usually corresponds to it's menu title in the Services menu.

echo "$PWD" | nxpasteboard --service "Terminal/Open shell here"

If service returns any text, it will be written back to the standard output.

.SH OPTIONS
.P
--copy copy text from standard input to the pasteboard

--paste paste text from the pasteboard to standard output

--service <name> call service with text from standard input
.P
21 changes: 21 additions & 0 deletions Tools/nxpasteboard.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/* Include for nxworkspace tools
Copyright (C) 2020 Free Software Foundation, Inc.

Written by: onflapp
Created: September 2020

This file is part of the GNUstep Project

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.

You should have received a copy of the GNU General Public
License along with this program; see the file COPYING.
If not, write to the Free Software Foundation,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.

*/

void printUsage();
127 changes: 127 additions & 0 deletions Tools/nxpasteboard.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
/* Copyright (C) 2020 Free Software Foundation, Inc.

Written by: onflapp
Created: September 2020

This file is part of the NEXTSPACE Project

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.

You should have received a copy of the GNU General Public
License along with this program; see the file COPYING.
If not, write to the Free Software Foundation,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.

*/

#import <AppKit/AppKit.h>

void printUsage() {
fprintf(stderr, "Usage: nxpasteboard [--copy] [--paste] [--service <name>]\n");
fprintf(stderr, "\n");
fprintf(stderr, "Help: gives you copy&paste and system services from command line\n");
fprintf(stderr, "Options:\n");
fprintf(stderr, " --copy copy text from standard input to the pasteboard\n");
fprintf(stderr, " --paste paste text from the pasteboard to standard output\n");
fprintf(stderr, " --service <name> call service with text from standard input\n");
fprintf(stderr, "\n");
}

int main(int argc, char** argv, char** env) {

NSProcessInfo *pInfo;
NSArray *arguments;
CREATE_AUTORELEASE_POOL(pool);

#ifdef GS_PASS_ARGUMENTS
[NSProcessInfo initializeWithArguments:argv count:argc environment:env_c];
#endif

pInfo = [NSProcessInfo processInfo];
arguments = [pInfo arguments];
int rv = 1;

@try {
if ([arguments count] == 1) {
printUsage();
rv = 1;
}
else if ([arguments containsObject: @"--copy"] == YES) {
NSFileHandle *sin = [NSFileHandle fileHandleWithStandardInput];
NSData* data = [sin readDataToEndOfFile];
if ([data length] > 0) {
NSString* str = [[NSString alloc ]initWithData:data encoding:NSUTF8StringEncoding];
NSPasteboard *pboard = [NSPasteboard generalPasteboard];
[pboard declareTypes:[NSArray arrayWithObject:NSPasteboardTypeString] owner:nil];
[pboard setString:str forType:NSPasteboardTypeString];
rv = EXIT_SUCCESS;
}
else {
rv = 4;
}
}
else if ([arguments containsObject: @"--service"] == YES) {
//suppress NSLog from NSApplication
fclose(stderr);

//register service types, this will refresh the service manager
id app = [NSApplication sharedApplication];
[app registerServicesMenuSendTypes:[NSArray arrayWithObject:NSPasteboardTypeString]
returnTypes:[NSArray arrayWithObject:NSPasteboardTypeString]];

NSFileHandle *sin = [NSFileHandle fileHandleWithStandardInput];
NSData* data = [sin readDataToEndOfFile];
if ([data length] > 0) {
NSString* serviceMenu = [arguments objectAtIndex:2];
NSString* str = [[NSString alloc ]initWithData:data encoding:NSUTF8StringEncoding];
NSPasteboard *pboard = [NSPasteboard pasteboardWithUniqueName];
[pboard declareTypes:[NSArray arrayWithObject:NSPasteboardTypeString] owner:nil];
[pboard setString:str forType:NSPasteboardTypeString];

BOOL done = NSPerformService(serviceMenu, pboard);

if (done) {
str = [pboard stringForType:NSPasteboardTypeString];
if (str) {
printf("%s", [str UTF8String]);
}
rv = EXIT_SUCCESS;
}
else {
rv = 4;
}
}
else {
rv = 4;
}
}
else if ([arguments containsObject: @"--paste"] == YES) {
NSPasteboard *pboard = [NSPasteboard generalPasteboard];
NSString* str = [pboard stringForType:NSPasteboardTypeString];
if (str) {
printf("%s", [str UTF8String]);
rv = EXIT_SUCCESS;
}
else {
rv = 4;
}
}
else {
printUsage();
rv = 1;
}
}
@catch (NSException* ex) {
NSLog(@"exception %@", ex);
printUsage();
rv = 6;
}

RELEASE(pool);

exit(rv);
}

Loading