Do you need to operate the command line frequently?
Do you ever feel like you’ve used a command so many times that you forget how to write it the next time you use it?
Or do you remember most of the command, but not exactly what it is?
Or are common commands at work so long that each input takes too long? You can say I’m using aliases for all my frequently used commands. How can I easily carry my hard-configured aliases when I switch computers?
By asking so many questions above, do you tap into some of your deepest needs? Then Tmax comes, in order to solve the above pain point, with the speed of lightning ⚡️ and come, next with me to understand the content of Tmax, I believe that after reading you will want to try.
What is tmax?
Tmax is a command line tool that helps you execute commands at lightning-fast ⚡️ speed for efficiency, while giving quick hints to help you complete tasks when you can’t remember the details.
The design idea of tmax
- Have a basic K8S CMD knowledge base that can be continuously enriched
- Efficient query algorithm and smooth command line interaction
- Shorten your usual super-long command line
What will Tmax bring you?
Tmax has 3 interactive modes: Direct mode, Search mode and Interactive mode. The usage and usage scenarios of these modes are described in the following GIF.
Before use, we need to execute tmax generate to generate a basic configuration file with the following content and format:
custom:
- check: curl 127.0. 01.:8080/health
k8s:
- filternodecpu: kubectl get nodes -o=jsonpath="{range .items[*]}{.metadata.name}{'\t'}{.status.capacity.cpu}{'\t'}{.status.capacity.memory}{'\n'}{end}"
- filternodetaint: kubectl get nodes -o=jsonpath="{range .items[*]}{.metadata.name}{'\t'}{.spec.taints[*].key}{'\n'}{end}"
- corednsedit: kubectl edit cm coredns -nkube-system
- allnode: kubectl get no
- alldeploy: kubectl get deploy
- allpod: kubectl get pod -A
- busyboxrun: kubectl run busybox --rm -ti --image=busybox /bin/sh
- allnodeip: kubectl get node -o=jsonpath="{range .items[*]}{.metadata.name}{'\t'}{.status.addresses[0].address}{'\n'}{end}"
- podResource: kubectl get pod -o custom-columns=NAME:metadata.name,podIP:status.podIP,hostIp:spec.containers[0].resources
- getns: kubectl get ns
- createdemo: kubectl create deployment nginx --image=nginx
- exposedemo: kubectl expose deployment nginx --port=80
- getnetwork: kubectl get networkpolicy
- runbox: kubectl run busybox --rm -ti --image=busybox /bin/sh
unix:
- "tar": "tar -xjvf test.tar.bz2"
Copy the code
For example, k8S is a group. This group has many command lines related to K8S. The abbreviation of the command line is key, and the real execution is value. For the same reason, you can customize or add content.
direct mode
As the name implies, direct mode directly executes the value of a key in the configuration file. For example, using tmax check is equivalent to using curl 127.0.0.1:8080/health, Kubectl run busybox –rm -ti –image=busybox /bin/sh — kubectl run busybox –rm -ti –image=busybox /bin/sh
search mode
Obviously, direct Mode is used when you are very familiar with certain commands, so if some of the commands are not very common, but you remember some of the keywords in the command, then using search mode is very suitable. For example, if you remember a command to quickly run a temporary busybox container in your configuration file, but can’t remember exactly how to write it or if you want to call out the command in a faster way, You can use tmax s box press enter and use ↓ ↑ → ← or you are a vim fan. You can also use J k to move up and down to select the command you want to execute and press Enter again to execute it.
When you do not want to execute this command, only for query function is also ok, tmax default configuration file built-in many commonly used kubectl command template, according to the function divided into get, create, run, label, etc., command template between the use of */* split, this part can not directly enter the execution. For use only as queries, of course you can continue to enrich these templates.
interactive mode
The application scenarios of interactive mode are as follows:
-
When you want to perform a set of actions or are stuck on the command line for a long time;
-
The command to execute can not remember the keyword, to query several times;
-
More frequent query actions.
Enter tmax and press Enter to enter interactive mode. Let’s watch a demo:
Interactive mode provides fast query speed and dynamic execution mode, combined with the TAB key completion mode, can be said to be lightning fast.
The above are the three use modes of TMAX at present, which can meet the needs of different scenarios. In addition, tmax provides the following features:
tmax regen
Regenerate the configuration filetmax add group:key:value
Add command, example:tmax add k8s:getns:kubectl get ns -A
tmax clear
Deleting a Configuration File
For details, run tmax –help.
Compilation and Installation
Tmax is currently only tested on Linux and Mac OS. It should be available on Win, but not tested.
- Compile: In the tmax project directory, execute
make build
, you get the executable filetmax
chmod +x tmax && cp tmax /usr/local/bin
You can use
A faster installation method will be provided later.
Some ideas
The initial power of tMAX development comes from the needs of their daily work. After a large number of applications use K8S cluster containerization, they often need to manage, eliminate barriers, query and other operations on the cluster. In a certain period of time, they will frequently execute some Kubectl commands, or some commands are particularly long. Or kubectl’s advanced query syntax is too difficult to remember, such as JSONPath, CUSTOMe-column query, for example, 🌰, where the leader wants you to quickly export the names of all nodes in the cluster and their resource configuration, you need to use JsonPath to loop the query:
kubectl get nodes -o=jsonpath="{range .items[*]}{.metadata.name}{'\t'}{.status.capacity.cpu}{'\t'}{.status.capacity.memory}{'\n'}{end}"
Copy the code
Commands like this can be added to the tmax configuration file and easily found when you forget the syntax or want to use it again.
It only takes a few days to develop Tmax intensively. The current beta version can only meet the basic requirements (the author has started to use tMAX at work). There are a lot of imperfections, which will be continuously enriched and enhanced in the future. Github.com/hantmac/tma…