[PYTHON] Summary of tools used in Command Line vol.5

Introduction

The Tool used in the Command Line is simple, but I'd like to summarize it. Continuing from the last time. There are still many useful tools I don't know, so If you find something useful other than the ones listed here, please let us know.

The link pasted in this article will take you to the appropriate place related to the keyword. It is very effective, so please refer to it.

Also, since I basically don't know anything about personal computers, there is a possibility that the article may contain errors. Therefore, I hope that you will read it in a timely manner after understanding your environment as much as possible. I think. In particular, please be careful about the location of the configuration file. Also, please note that the introduction explanation of Git, Homebrew, and MacPort is omitted.

Also, I will omit the explanation that I think I introduced last time, such as how to introduce the pip command.

zsh

Convenient use of zsh command line stack

zsh has a function to temporarily save commands. By doing the following, you can save commands after displaying the commands saved with C-q.

~/.zshrc


# C-Execute the command line stack with q. In addition, display the saved commands.
# http://d.hatena.ne.jp/kei_q/20110308/1299594629
# http://qiita.com/items/1f2c7793944b1f6cc346

show_buffer_stack() {
  POSTDISPLAY="
stack: $LBUFFER"
  zle push-line-or-edit
}
zle -N show_buffer_stack
setopt noflowcontrol
bindkey '^Q' show_buffer_stack

The above explanation is a little difficult to understand. So, let's think about a specific case.

For example, in the case of "trying to copy a file to a specific folder, but notice that the folder does not exist here".

$ cp miku.mp3 ~/Download/Chrome/App/Media //… Notice that there is no folder at this point
 
[C-q] //… Run command line stack
 
$ mkdir -p ~/Download/Chrome/App/Media //… Execute the command to create a folder
 
$ cp miku.mp3 ~/Download/Chrome/App/Media //… Automatically saved commands appear

The command line stack can be used like this.

Record the displayed command to the clipboard

If you want to record the displayed command to the clipboard, the following setting file is effective. Now you can record the displayed command to the clipboard by pressing Cx, Cp. I will.

~/.zshrc


# http://d.hatena.ne.jp/hiboma/20120315/1331821642
pbcopy-buffer(){
    print -rn $BUFFER | pbcopy
    zle -M "pbcopy: ${BUFFER}"
}
 
zle -N pbcopy-buffer
bindkey '^x^p' pbcopy-buffer

zmv In zsh, you can move files in batch as follows, but batch renaming is quite troublesome, so use zaw. ¡

mv *.{flv,mp4,swf} ~/Movie
#In the folder.mp3.Make it mp4
zmv -W '*.mp3' '*.mp4'

And if you write the following settings, you can omit single quotes etc., which is convenient.

~/.zshrc


autoload -Uz zmv
alias zmv='noglob zmv -W'

atool atool is an assortment of tools that decompress files such as compressed files by judging from the extension. Installation and usage are as follows. It is recommended for people who do not have the decompression command for compressed files with various extensions in mind and do not feel like remembering it. I am.

atool installation

sudo port install atool

How to use atool

#Defrost
anupack  hoge.tar.gz

#compression
apack  moge.tar.bz2  moge

#Check the contents of the archive
als  hogemoge.tar.gz

People who wrote a special configuration file who has not used ʻatool` until now is as follows. Then it may be easy.

alias -s {gz,tgz,zip,lzh,bz2,tbz,Z,tar,arj,xz}=aunpack

pyful pyful is a filer written in Python. I usually do a little troublesome file operation with VimFiler. However, if you want to operate files for a long time, you may use pyful. By the way, pyful is very versatile and can be used for other than filers, so it is very convenient.

pyful installation

sudo pip install pyful

How to use pyful

It is written in great detail on here, so I don't think it is necessary to explain it, but I will briefly explain what I often use personally.

Filer


Q //End
h //Command line
M-RET //Create a new directory screen
M-C, C-w //Delete the current directory screen
<end> //Mark all files toggle
* //Mark files that match the regular expression
f, / //Incremental search started
R //Batch replacement of file names with regular expressions
M-? //Show all help

Command line


M-i //Launch action box
M-m //Expand macro
M-y //Activate clipboard mode

pyful config file

To master pyful, it is important to customize the configuration file.

pyful> Make external command execution compatible with tmux

rc.py


# Set screen command and arguments.
# https://github.com/anmitsu/pyful/wiki/tips
#     {TITLE} is replaced to window title in screen.
#     {COMMAND} is replaced to a command in screen.
import os
if os.getenv("TMUX"):
    # For tmux:
    pyful.process.Process.screen_command = ("tmux", "neww", "-n", "{TITLE}", "{COMMAND}")
else:
    # For GNU Screen:
    pyful.process.Process.screen_command = ("screen", "-t", "{TITLE}", "bash", "-c", "{COMMAND}")

pyful> Show bookmark menu

rc.py


menu.items["bookmark"] = (
    ("/(u)sr" , "u", lambda: filer.dir.chdir("/usr")),
    ("/(e)tc" , "e", lambda: filer.dir.chdir("/etc")),
    )

pyful> Manipulate the clipboard

#Set the file name under the cursor to the clipboard
echo -n %f | xsel -b

#Set the absolute path of the file under the cursor to the clipboard
echo -n %F | xsel -b

#Set the marked file contents to the clipboard
cat %m | xsel -b

By doing the following, you can "save the absolute path of the file under the cursor to the clipboard" with the N key.

rc.py


# https://github.com/anmitsu/pyful/wiki/tips
menu.items["xsel"] = (
    ("name copy"          , "n", lambda: process.spawn("%q echo -n %f | xsel -b")),
    ("absolute path copy" , "N", lambda: process.spawn("%q echo -n %F | xsel -b")),
    ("fileCopy"           , "F", lambda: process.spawn("%q cat %m | xsel -b")),
    )

mc As a filer, I used to use mc for a while.

It ends with F10. You can intuitively understand other operation methods.

Nexus7 This time, I'm going to write on the theme of CLI with Nexus7.

Erase Android and install Ubuntu

The default boot loader for Android is locked, so you need to unlock it. When you unlock the boot loader, the settings will be initialized, so be careful (backup required).

To unlock it, you need a toolkit that is vulnerable and steals privileges.

Nexus 7 rooting method / procedure.

Ubuntu


sudo add-apt-repository ppa:ubuntu-nexus7/ubuntu-nexus7-installer
 
sudo apt-get update
 
sudo apt-get install ubuntu-nexus7-installer

Press and hold the volume down button and power button on the Nexus 7 at the same time to start the boot loader. All you have to do is start the Ubuntu Nexus 7 Installer and follow the wizard. During this time, keep your computer and device connected via USB.

Native installation of Ubuntu on Nexus 7

Install UBUNTU in virtual environment

This is the procedure to start Ubuntu on Android. Complete Linux Installer and Android Terminal Emulator //android-terminal-emulator.softonic.jp/android), and VNC Client For example, Android VNC Viewer Is installed.

Then use the Complete Linux Installer to download the required files and launch Ubuntu from Launch.

After that, you can operate the desktop by connecting to VNC with VNC Client.

Linux with Chinese pad (2)

CLI with ANDROID

Download Term20121110.apk, attach it to Gmail, and install it.

cd ~/Downloads/

w3m http://ux.getuploader.com/android_files/

mutt -n -F settings.txt -s "SUBJECT" [email protected] -a Term20121110.apk < body.txt

All you need to do is check Security → "Apps from unknown sources", send an email with an apk file to your Android Gmail address, and open it.

Cui on Nexus 7

I entered tmux.

How to install apk file obtained from other than store on Android

How to send an email using mutt

Recommended apps

It has nothing to do with CLI, but I would like to introduce it in the recommended application of Nexus 7.

Vim Touch This app is that you can use Vim on Android. It's nice that this site is very easy to understand when using Nexus 7.

Android Terminal Emulator It's an indispensable app. Android has such an app, so it's good. Of course, if iOS also takes root, there is such an app ....

Perfect Viewer Comic viewer with PDF plug-in. Used to read e-books.

VLC for Android Beta A classic and multifunctional video player.

Google Japanese Input It complements Japanese more appropriately than other input support apps.

Astro File Manager This is the best file manager. For now.

Fing A network scanner that is becoming a standard.

Olive Office Premium Supports various Office-related extensions.

SketchBook Express for Tablets High-performance drawing app.

Jorte Calendar, schedule management, etc.

Dropbox Dropbox is familiar with file sharing. Personally, it is essential because the configuration file is managed by Dropbox, not via Github.

Pixlr Express A photo editing app that makes it easy to get a professional finish.

exFAT If you want to share files between Mac and Windows, it is recommended to format the HDD with ʻexFAT. Maybe you can format it by doing the following. Win key+RPress and typecmd`. The command prompt will start.

Windows


#Format D drive with exFAT
convert D:/fs:exfat

By the way, if you want Linux to recognize the HDD formatted with ʻexFAT`, do as follows For Ubuntu

$ sudo add-apt-repository ppa:relan/exfat
 
$ sudo aptitude update
 
$ sudo aptitude upgrade
 
$ sudo aptitude install fuse-exfat

By the way, if you have an old computer (XP, etc.), you can format it by downloading and installing a special package.

That's all for this time. I'm sorry I couldn't introduce the tool I announced last time. If I have a chance to take a screenshot, I'll introduce it. Thank you.

Summary of tools used in Command Line vol.1

Summary of tools used in Command Line vol.2

Summary of tools used in Command Line vol.3

Summary of tools used in Command Line vol.4

Recommended Posts

Summary of tools used in Command Line vol.5
Summary of methods often used in pandas
Summary of frequently used commands in matplotlib
Summary of OSS tools and libraries created in 2016
Summary of what was used in 100 Pandas knocks (# 1 ~ # 32)
Summary of evaluation functions used in machine learning
Summary of tools needed to analyze data in Python
Summary of how to write .proto files used in gRPC
Summary of various operations in Tensorflow
Grammar summary often used in pandas
Summary of "nl command Advent Calendar 2020"
[Anaconda3] Summary of frequently used commands
Frequently used command line shortcut keys (Mac)
Summary of various for statements in Python
Summary of stumbling blocks in installing CaboCha
Decompose command arguments in one line in Python
Summary of modules and classes in Python-TensorFlow2-
Summary of built-in methods in Python list
Introduction of SoftLayer Command Line Interface environment
Template for creating command line applications in Python
How to receive command line arguments in Python
[Python/Django] Summary of frequently used commands (3) <Operation of PostgreSQL>
Summary of how to import files in Python 3
Full disclosure of methods used in machine learning
Summary of how to use MNIST in Python
The story of misreading the swap line of the top command
Fix the argument of the function used in map
Summary of frequently used Python arrays (for myself)
[Linux command] A memorandum of frequently used commands
[Python/Django] Summary of frequently used commands (2) <Installing packages>
Summary of frequently used commands (with petit commentary)
Selenium webdriver Summary of frequently used operation methods
Summary of Excel operations using OpenPyXL in Python
Linux Command Summary
Docker command summary
Used from the introduction of Node.js in WSL environment
Specify a subcommand as a command line argument in Python
Open Chrome version of LINE from the command line [Linux]
A collection of code often used in personal Python
Existence check of external command in Python (like `which`)
Summary of tools for operating Windows GUI with Python
A collection of commands frequently used in server management
Summary of Pandas methods used when extracting data [Python]
List of Python code used in big data analysis
Command line collection for using virtual environment in Anaconda
A collection of Excel operations often used in Python
Summary of date processing in Python (datetime and dateutil)