Neomutt Pipe Attachments to Shell Program from Menu - shell

The header of the attachments menu in neomutt gives the options
q:Exit s:Save |:Pipe p:Print ?:Help
I assumed that the Pipe option would allow me to pipe a chosen attachment to the shell. In particular, maybe I want to open a file in a way that bypasses the mailcap defaults.
Suppose I wanted to open a file from the attachment menu with open. Is there a way to achieve this with Pipe and not by going to edit my mailcap?
Thanks

The only downfall of this is you need to specify all types, because wildcard can be only in subtype - */* or * doesn't work
Store original mailcap file location in a variable
Define macro in attach menu that changes mailcap file to a new one, run view-attach (which uses open to open a file with) and return to original mailcap_path configuration.
~/.muttrc
set my_origmailcap=$mailcap_path
macro attach <Space> "\
<enter-command>set mailcap_path=~/.mailcap2<enter>\
<view-attach>\
<enter-command>set mailcap_path=$my_origmailcap<enter>\
"
~/.mailcap2
audio/* ; open %s
image/* ; open %s
text/* ; open %s
video/* ; open %s

Related

sql loader without .dat extension

Oracle's sqlldr defaults to a .dat extension. That I want to override. I don't like to rename the file. When googled get to know few answers to use . like data='fileName.' which is not working. Share your ideas, please.
Error message is fileName.dat is not found.
Sqlloder has default extension for all input files data,log,control...
data= .dat
log= .log
control = .ctl
bad =.bad
PARFILE = .par
But you have to pass filename without apostrophe and dot
sqlloder pass/user#db control=control data=data
sqloader will add extension. control.ctl data.dat
Nevertheless i do not understand why you do not want to specify extension?
You can't, at least in Unix/Linux environments. In Windows you can use the trailing period trick, specifying either INFILE 'filename.' in the control file or DATA=filename. on the command line. WIndows file name handling allows that; you can for instance do DIR filename. at a command prompt and it will list the file with no extension (as will DIR filename). But you can't do that with *nix, from a shell prompt or anywhere else.
You said you don't want to copy or rename the file. Temporarily renaming it might be the simplest solution, but as you may have a reason not to do that even briefly you could instead create a hard or soft link to the file which does have an extension, and use that link as the target instead. You could wrap that in a shell script that takes the file name argument:
# set variable from correct positional parameter; if you pass in the control
# file name or other options, this might not be $1 so adjust as needed
# if the tmeproary file won't be int he same directory, need to be full path
filename=$1
# optionally check file exists, is readable, etc. but overkill for demo
# can also check temporary file does not already exist - stop or remove
# create soft link somewhere it won't impact any other processes
ln -s ${filename} /tmp/${filename##*/}.dat
# run SQL*Loader with soft link as target
sqlldr user/password#db control=file.ctl data=/tmp/${filename##*/}.dat
# clean up
rm -f /tmp/${filename##*/}.dat
You can then call that as:
./scriptfile.sh /path/to/filename
If you can create the link in the same directory then you only need to pass the file, but if it's somewhere else - which may be necessary depending on why renaming isn't an option, and desirable either way - then you need to pass the full path of the data file so the link works. (If the temporary file will be int he same filesystem you could use a hard link, and you wouldn't have to pass the full path then either, but it's still cleaner to do so).
As you haven't shown your current command line options you may have to adjust that to take into account anything else you currently specify there rather than in the control file, particularly which positional argument is actually the data file path.
I have the same issue. I get a monthly download of reference data used in medical application and the 485 downloaded files don't have file extensions (#2gb). Unless I can load without file extensions I have to copy the files with .dat and load from there.

How can I find the particular file in a Project/Folder in Sublime Text

I know that using ctrl+shift+f we can find the text in folder we want and simple ctrl+f will find the text in a opened file or we can right folder and click on a option Find in Folder... to search the text
I am looking for, how can I find the file in a Folder/Project.
You can use the Goto Anything feature (Ctrl+P on Windows and Linux, Cmd+P on macOS) and type the name of the file you're looking for. If there are multiple hits, you can select the appropriate file using cursor keys. It also supports powerful operators, that let you jump to specific parts inside a file.
Examples:
file.js opens that file
:100 jumps to line 100 in current file
file.js:100 jumps to line 100 in file.js
#loadFile lists all files with classes/functions named loadFile (shortcut: Ctrl+R, Cmd+R on macOS)
file.js#loadFile jumps to a loadFile() in file.js
This can be done using:
Windows: Ctrl + P
Mac: Cmd + P
It works much like ItelliJ's Shift - 2 times, with a faster and accurate prediction.

QBasic - How do you create a file of any kind in QBasic?

I'm trying to create a batch file, a text file, and a DLL file via QBasic?
Please help me... I'm making a fake DOS.
That's old :)
If i remind:
To Open files: (you can create, read and write)
Open (Path and file name) For (Mode) [Access (Type of access)] As #(File number)
Where:
(Path and file name) - The path and name of the destination file
(Mode) - You can set one of this values:
Input: Read Mode
Binary: Structured data
Output: Write Mode - If the file already exist - overwrites the file.
Append: The difference between this and Output is that if the file already exists, the content is appended to the end of the file
(Access type) - Kind of access.
Read: Read-Only access.
Write: Write-Only access.
Read Write: Available only in Append Mode
(File number) - Identifies the file, like a pointer to it.
To close a file, just use:
Close [#(FileNumber)][, #(FileNumber) ...]
Yes you can close more than one file at a time, and if you don't specify the file number, qbasic will close all your opened files.
Note that in Append and Output mode, you must first close the file before you open it for reading!
Ok, to read\write use the same you use on screen, but append the file destination:
Input (Char Length), #(File number), (Name of the Variable)
Line Input #(File number), (Name of the Variable)
Print #(File number), (Data) [or (Binary data)]
If you don't remember to give the carriage-return (commonly \n) use the ASCII char: Chr(10)
Example:
Open "c:\test.bat" for Output as #1
Print #1, "#echo off" + Chr$(10)
Print #1, "echo Hello World"
Close #1
End

How to (easily) get current file path in Sublime Text 3

How to (easily) get current file path in Sublime Text 3
I don't often use ST console (I used it only once to install package manager), but I suppose it could be good way to :
get current file path like some kind pwd command.
But it doesn't work.
Does anyone know an easy way to get current file path?
to clipboard : better not a strict objective in the answer
not necessary by ST command, maybe package?
Right click somewhere in the file (not on the title tab) --> Copy file path
If you don't want to use the mouse, you could set up a keyboard shortcut as explained here https://superuser.com/questions/636057/how-to-set-shortcut-for-copy-file-path-in-sublime-text-3
To easily copy the current file path, add the following to Key Bindings - User:
{ "keys": ["ctrl+alt+c"], "command": "copy_path" },
Source
Key Bindings - User can be opened via the command palette (command + p on OSX)
Easy to understand using image. On Right Click you will get this.
Transcribed code in image for convenience:
import sublime, sublime_plugin, os
class CopyFilenameCommand(sublime_plugin.TextCommand):
def run(self, edit):
if len(self.view.file_name()) > 0:
filename = os.path.split(self.view.file_name())[1]
sublime.set_clipboard(filename)
sublime.status_message("Copied file name: %s" % filename)
def is_enabled(self):
return self.view.file_name()... # can't see
Mac OS X - Sublime Text 3
Right click > Copy File Path
A lot of these answers involve touching the mouse. Here's how to do get the path without any mouse clicks using SideBarEnhancements
Install SideBarEnhancements using PackageControl.
Click super + shift + P to open the command palette
In the command palette begin typing path until you see File: Copy Path
Select File: Copy Path
Now the path to file you are working in is copied into your clipboard.
There is a Sublime Package which gives your current file location inside a status bar. I just cloned them directly to my /sublime-text-3/Packages folder.
git clone git#github.com:shagabutdinov/sublime-shell-status.git ShellStatus;
git clone git#github.com:shagabutdinov/sublime-status-message.git StatusMessage;
You have to check/read the description on GitHub. Even it is listed in package control it would not install properly for me. You can actually edit the shell output as you want. If you have the right skills with python/shell.
Looks like this (Material Theme)
If you're like me and always click on items in the sidebar just to realize that copying the path only works when clicking in the editor area, have a look at the SideBarEnhancements package. It has a huge bunch of options to copy file paths in a variety of different ways.
Installation is available via Package Control (despite the webpage only mentions installation via manual download).
Note: The package “sends basic, anonymous statistics”. The webpage explains how to opt out from that.
Go to this link. The code in the link is given by robertcollier4.
Create a file named CpoyFileName.py or whatever you like with .py extension.
Save the file in Sublime Text 3\Packages\User folder. Then paste the above given key bindings in your Preferences: Key Bindings file.
Now, you can use the specified key bindings to copy just filename or total (absolute) filepath.
Please note that the filename or filepath do contain file extension.
Fastest Solution ( No Packages Needed + Comprehensive ):
Folder Path:
Folder in "Sidebar"
Right Click
"Find In Folder"
"Where" field contains everything you need
File Path:
File in current "Tab"
Right Click
"Copy File Path"

How can I make org-protocol work on Openbox?

I tried the instructions - I am using Firefox on Lubuntu (Openbox). But I get the error
"Firefox doesn't know how to open this address, because the protocol (org-protocol) isn't associated with any program".
How should I fix this?
The following steps for setting up org-protocol work with Ubuntu 16.04 (Xenial Xerus) and presumably later versions. Org-mode is assumed to have already been set-up (and installed using apt-get install org-mode or via the ELPA repository).
Set-up
Add .desktop file
Create and save a file called org-protocol.desktop to ~/.local/share/applications containing:
[Desktop Entry]
Name=org-protocol
Exec=emacsclient %u
Type=Application
Terminal=false
Categories=System;
MimeType=x-scheme-handler/org-protocol;
Then run:
$ update-desktop-database ~/.local/share/applications/
This step makes Firefox aware that "org-protocol" is a valid scheme-handler or protocol (by updating ~/.local/share/applications/mimeinfo.cache), and causes Firefox to prompt for a program to use when opening these kinds of links.
Add config settings to ~/.emacs.d/init.el (or ~/.emacs) file
Have the following settings in your Emacs configuration file:
(server-start)
(require 'org-protocol)
Also add some template definitions to the configuration file, for example:
(setq org-protocol-default-template-key "l")
(setq org-capture-templates
'(("t" "Todo" entry (file+headline "/path/to/notes.org" "Tasks")
"* TODO %?\n %i\n %a")
("l" "Link" entry (file+olp "/path/to/notes.org" "Web Links")
"* %a\n %?\n %i")
("j" "Journal" entry (file+datetree "/path/to/journal.org")
"* %?\nEntered on %U\n %i\n %a")))
Now run Emacs.
Create your notes.org file
Assuming you use the capture templates defined in step 2, you will need to prepare a notes.org file at the location you specified in step 2. You must create this file -- if it is not created along with the headlines specified in step 2, org-mode will just give a warning when you try to capture web-pages. So, given the capture templates from step 2, notes.org should contain the following:
* Tasks
* Web Links
Add bookmarklet(s) to Firefox
Save bookmark to toolbar containing something like the following as the location:
javascript:location.href='org-protocol://capture?template=l&url='+encodeURIComponent(location.href)+'&title='+encodeURIComponent(document.title)+'&body='+encodeURIComponent(window.getSelection())
If you are using an older version of org-mode, you may need to use the following instead:
javascript:location.href='org-protocol://capture://l/'+encodeURIComponent(location.href)+'/'+encodeURIComponent(document.title)+'/'+encodeURIComponent(window.getSelection())
Notice the 'l' (lowercase L) in the above URL -- this is what chooses the capture template (automatically) -- it is the key one would normally have to press when capturing with org-mode via C-c c.
When you click on this bookmarklet, Firefox will ask what program to use to handle the "org-protocol" protocol. You can simply choose the default program that appears ("org-protocol").
Using it
(Optionally) select some text on a webpage you're viewing in Firefox. When you click on the bookmarklet, the link and selected text will be placed in the Emacs capture buffer. Go to Emacs, modify the capture buffer as desired, and press C-c C-c to save it.
Add protocol handler
Create file ~/.local/share/applications/org-protocol.desktop containing:
[Desktop Entry]
Name=org-protocol
Exec=emacsclient %u
Type=Application
Terminal=false
Categories=System;
MimeType=x-scheme-handler/org-protocol;
Note: Each line's key must be capitalized exactly as displayed, or it will be an invalid .desktop file.
Then update ~/.local/share/applications/mimeinfo.cache by running:
On GNOME:
update-desktop-database ~/.local/share/applications/
On KDE:
kbuildsycoca4
Configure Emacs
Init file
Add to your Emacs init file:
(server-start)
(require 'org-protocol)
Capture template
You'll probably want to add a capture template something like this:
("w" "Web site"
entry
(file+olp "/path/to/inbox.org" "Web")
"* %c :website:\n%U %?%:initial")
Note: Using %:initial instead of %i seems to handle multi-line content better.
This will result in a capture like this:
\* [[http://orgmode.org/worg/org-contrib/org-protocol.html][org-protocol.el – Intercept calls from emacsclient to trigger custom actions]] :website:
[2015-09-29 Tue 11:09] About org-protocol.el
org-protocol.el is based on code and ideas from org-annotation-helper.el and org-browser-url.el.
Configure Firefox
Expose protocol-handler
On some versions of Firefox, it may be necessary to add this setting. You may skip this step and come back to it if you get an error saying that Firefox doesn't know how to handle org-protocol links.
Open about:config and create a new boolean value named network.protocol-handler.expose.org-protocol and set it to true.
Note: If you do skip this step, and you do encounter the error, Firefox may replace all open tabs in the window with the error message, making it difficult or impossible to recover those tabs. It's best to use a new window with a throwaway tab to test this setup until you know it's working.
Make bookmarklet
Make a bookmarklet with the location:
javascript:location.href='org-protocol://capture://w/'+encodeURIComponent(location.href)+'/'+encodeURIComponent(document.title)+'/'+encodeURIComponent(window.getSelection())
Note: The w in the URL chooses the corresponding capture template. You can leave it out if you want to be prompted for the template.
When you click on this bookmarklet for the first time, Firefox will ask what program to use to handle the org-protocol protocol. If you are using Ubuntu 12.04 (Precise Pangolin), you must add the /usr/bin/emacsclient program, and choose it. With Ubuntu 12.10 (Quantal Quetzal) or later, you can simply choose the default program that appears (org-protocol).
You can select text in the page when you capture and it will be copied into the template, or you can just capture the page title and URL.
Tridactyl
If you're using Tridactyl, you can map key sequences something like this:
bind cc js location.href='org-protocol://capture://w/'+encodeURIComponent(content.location.href)+'/'+encodeURIComponent(content.document.title)+'/'+encodeURIComponent(content.document.getSelection())
You might also want to add one for the `store-link` sub-protocol, like:
bind cl js location.href='org-protocol://store-link://'+encodeURIComponent(content.location.href)+'/'+encodeURIComponent(content.document.title)
Capture script
You may want to use this script to capture input from a terminal, either as an argument or piped in:
#!/bin/bash
if [[ $# ]]
then
data="$#"
else
data=$(cat)
fi
if [[ -z $data ]]
then
exit 1
fi
encoded=$(python -c "import sys, urllib; print urllib.quote(' '.join(sys.argv[1:]), safe='')" "${data[#]}")
# "link" and "title" are not used, but seem to be necessary to get
# $encoded to be captured
emacsclient "org-protocol://capture://link/title/$encoded"
Then you can capture input from the shell like this:
tail /var/log/syslog | org-capture
org-capture "I can capture from a terminal!"
These instructions are more up-to-date than the ones in Mark's answer.

Resources